Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation.setFillAfter/Before - Do they work/What are they for?

As in the title of my question what are the methods setFillBefore() and setFillAfter() supposed to do?

I was hoping setFillAfter() would make the change to the View permanent after an animation has completed, but this is incorrect?

like image 917
D-Dᴙum Avatar asked May 04 '11 16:05

D-Dᴙum


People also ask

What is fillAfter animation in Android?

android:fillAfterIf fillEnabled is not set to true and the animation is not set on a View, fillAfter is assumed to be true. May be a boolean value, such as " true " or " false ". Related methods: setFillAfter(boolean)

What are animations on Android?

Animation is the process of adding a motion effect to any view, image, or text. With the help of an animation, you can add motion or can change the shape of a specific view. Animation in Android is generally used to give your UI a rich look and feel.


1 Answers

The answer is yes, they do work, just probably not for what you expect - for instance, the description for setFillAfter(boolean fillAfter) says

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

and when set to true it does do this.

However, unintuitively an animation on Android does not actually animate the View itself, rather it animates a bitmap representation of the View.

The issue you are probably having is that after an animation the View goes back to being how it was before the animation - setFillAfter and setFillBefore cannot help you with that, because in that situation what you really want to do is set the properties of the View to be same as the animated representation (they are separate things), and setFillAfter and setFillBefore only apply to animation properties, not View properties.

The reason they exist is for chaining animations. Suppose you had a translate animation followed by a fade out. If you did not set setFillAfter(true) on the translate animation, then the View would translate, jump back to it's original position and then fade out. With setFillAfter(true) set on the translate animation, the view will move and then fade out at it's current spot.

like image 137
Joseph Earl Avatar answered Sep 28 '22 01:09

Joseph Earl