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);
totalitarian
  • 3,606
  • 6
  • 32
  • 55

1 Answers1

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.

daniel.gindi
  • 3,457
  • 1
  • 30
  • 36
Umar Qureshi
  • 5,985
  • 2
  • 30
  • 40
  • Is this the standard way I should be doing things or this there something wrong with clearanimation / fill methods? – totalitarian Aug 13 '12 at 16:17
  • if you want the animation to end at any point instantly (i.e using clearAnimation which i think is quiet fine for this scenario) then this is the correct way to do this as far as i know. and it was accepted by majority as i was also in situation where i have to use fillEnable false then i followed same procedure discussed in following questions http://stackoverflow.com/questions/7824079/edittext-stucks-after-animation-and-alive-back-on-scrolling http://stackoverflow.com/questions/8411903/android-translateanimation-on-button-flickers/8411992#8411992 – Umar Qureshi Aug 13 '12 at 17:30
  • Thanks. Calling invalidate() after clearAnimation seems to do the trick in my case. – totalitarian Aug 13 '12 at 18:40