2

As part of a much more complex piece of functionality I've become stuck on the ability to show a circle becoming opaque at a certain point of the screen.

I've gone as far as to create a test project where my Animation code is as follows:

View mLongPressImage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLongPressImage = findViewById(R.id.onPressImage); findViewById(R.id.button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startAnimation(v.getX(), v.getY()); } }); } private AlphaAnimation onPressAnimation; private void startAnimation(final float f, final float g) { Log.v("", "START"); mLongPressImage.setX(f); mLongPressImage.setY(g); onPressAnimation = new AlphaAnimation(0f, 1f); onPressAnimation.setDuration(1000); onPressAnimation.setFillAfter(true); onPressAnimation.setFillEnabled(true); mLongPressImage.startAnimation(onPressAnimation); } 

Logging show's the correct event's are happening.

View looks like so:

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="PRESS ME" /> <ImageView android:id="@+id/onPressImage" android:layout_width="200dp" android:layout_height="200dp" android:background="#000000" android:scaleType="fitXY" android:src="@drawable/shape_circle_onpress" /> </FrameLayout> 

Right now the Image simply appears at the coordinates after 1 second has passed.

Can anybody point out the hidden flaw in this extremely simple piece of functionality?

2 Answers 2

1

The above code seems to be technically correct which is why I was having such a big problem solving it.

The issue was caused by me using setX() and setY() and Animation together - On my Xoom tablet (running 3.2 API 13) this caused some pretty funky behaviour even after switching to ScaleAnimation.

Removing the setX() and setY() removes the glitchy behaviour as does switching to a Galaxy Nexus (Running API 4.0 Icecream Sandwich). Setting hardwareAccelerated to true instead of removing the setX() and setY() also improved the problem (but didn't fix it completely).

If anyone know's why this is I'll be more than happy to upvote and change the accepted answer on this one. I'm going to chalk it up to a flakey Android API until then.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are unsatisfied with black background around circle, you can change ImageView background to following (notice two addtional zeros to describe alpha channel value):

android:background="#00000000"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.