0

Image this scenario, I have a bitmap travelling across the screen from left to right and a button which when pressed will call clearAnimation()

When this button is pressed, it calls clearAnimation() on the travelling bitmap but the bitmap stays in the position (somewhere between left and right) on the screen.

What I actually would like to happen is that when the button is pressed, the bitmap ends up at the end of the animation point (right of the screen)

Any idea how to achieve this please? Below is my animation code

questionAnimation = AnimationUtils.loadAnimation(QuestionActivity.this, R.anim.left_to_right);
questionWrapper.setBackgroundDrawable(getResources().getDrawable(R.drawable.imageview_rounded));
questionWrapper.startAnimation(questionAnimation);
4

1 に答える 1

1

i think what is happening to your animation is that its setFillAfter() is setted to true by default or either you have setted it to true before applying animation, through java or from xml so first you should set setFillAfter to false or you can directly change setFillEnabled to false like here in xml applied to set

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="false" >

<translate
    android:duration="300"
    android:fromYDelta="100%p"
    android:toYDelta="0" />

<alpha
    android:duration="300"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

</set>

Or

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillEnabled="false" >

<translate
    android:duration="300"
    android:fromYDelta="100%p"
    android:toYDelta="0" />

<alpha
    android:duration="300"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

</set>

hence in this case when animation ends or clears it won't retain views image (suspend your image in middle) so secondly you have to set the new place of your image i.e to the right of screen through code when you clear animation or animation ends up naturally, for that you have to place the actual view(ImageView) to new place (As this was being handled previously by FillAfter but due to its malfunctioning of suspending view on pressing clear animation you need to remove it so now you have to cover its functionality by urself) by setting properties of your ImageView like if it's in RelativeLayout then by setting property of AlignParentRight to true.

于 2012-08-13T15:02:45.873 に答える