views:

87

answers:

3

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 view to stay at that new size for the rest of the activities 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 tranformation?

I'm using myView.startAnimation(AnimationUtils.loadAnimation(mContext,R.anim.scaleUp150));

Thanks!

+1  A: 

EDIT: previous answer incorrect.

For things to work as expected after the animation, at least according to this thread, you will have to write an onAnimationEnd handler, and in there, manually adjust the "real" (pre-transformation) bounds of your view to match the end result of the scale animation.

Walter Mundt
Hi Walter. I have overwritten the onAnimationEnd, but I don't know how to adjust the "real" bounds of the view to match the scale of the animation. I do know what exact dp I want it to end up, but I can't find the function to "setWidth()" or "setHeight()".
justinl
I believe those are stored in the LayoutParams. You should be able to do `view.getLayoutParams().width = newWidth; view.getLayoutParams().height = newHeight; view.requestLayout();`. (The latter call is necessary to inform the view tree that it needs to be recalculated.)
Walter Mundt
oh excellent :D thanks! This is great
justinl
This is an incredibly roundabout way of doing things. All one needs to do is set attributes `android:fillEnabled` and `android:fillAfter` to both be true.
Neil Traft
+1  A: 

Actually, as the animation you are using seems to be one embedded in the Android framework, I'm not sure you can change anything in it.
However, you can create you own animation by following the example in the documentation. And you will have to put android:fillAfter="true" if you want the scaling to be kept after the end of the animation.

Sephy
scaleUp150 is a custom animation I wrote in xml (though it's extremely basic). I did put the android:fillAfter="true" inside the animation but it still snaps back to the original size :S
justinl
+3  A: 

fillAfter=true fillEnabled=true

Qlimax
This is the real answer. **The OP should change this to be the accepted answer.** Thank you Qlimax!! (P.S. this is not documented in the "Animation" section of the Dev Guide, it is only documented in the javadocs for the Animation class. Such poor documentation!)
Neil Traft