How to animate a view in Android and have it stay in the new position/size?
I currently have a view in my Android app and the view is playing a frame animation. I want to animate the view to increase its size to 150%. When I apply a scale animation to it, and the scale animation is completed, I want the viewer to stay at that new size for the rest of the activity's life cycle. Unfortunately right now when the scale-up animation is complete, the view snaps back to the original size. How can I get it to keep the new animated transformation?
I'm using
myView.startAnimation(AnimationUtils.loadAnimation(mContext,R.anim.scaleUp150));
Thanks!
Make sure you add below attributes to the root element in your animation xml:
android:fillAfter="true"
android:fillEnabled="true"
try constructing the animation from code and setting the properties like this
anim.setFillEnabled(true);
anim.setFillAfter(true);
if you want to put your animation in an xml, it may need this to help:
<set
android:fillEnabled="true"
android:fillAfter="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="-20%p"
android:duration="7000" />
</set>
https://stackoverflow.com/a/6519233/371749
please also appreciate the other answer, helped me :) good luck!