Reset animation effects in android

I perform the fade effect on the button.

AnimationSet set = new AnimationSet(true); Animation animation2 = new AlphaAnimation((float) 0, 1); animation2.setDuration(1500); animation2.setRepeatMode(0); set.addAnimation(animation2); set.setFillAfter(true); // leaves the animation in its final status btn.startAnimation(set); 

I use the setFillAfter(true) parameter to leave the button visible. It works great. Now I would like to perform the animation again , but I can never set it again so that my button is invisible on the screen if I do not restart the application. (alos tried to invalidate () without success ...)

Any idea would be "welcome."

Thanks in advance! Floor

+1
android animation
source share
2 answers

Thanks for helping. In fact, I found the answer to the developers document. There is a big difference between "View animation" (which I tried to make) and "Property Animation". Basically, viewing the animation redraws the image of the view you are viewing, but does not affect the original view. So, if you translate your opinion from an example, the view moves on the screen, but programmatically it remains in its original state and will capture events in its original position.

Here is an explanation:

How animation of objects differs from animation of viewing Animation of viewing provides an opportunity to animate View objects, therefore, if you wanted to animate objects without viewing, you must implement your own code for this. The view animation system is also limited in the fact that it provides only a few aspects of the View object for animation, such as scaling and rotating the view, but not the background color, for example.

Another drawback of the viewing animation system is that it was only changed when the view was displayed, and not the actual view. For example, if you animated a button to move around the screen, the button draws correctly, but the actual location where you can click the button does not change, so you need to implement your own logic to handle this.

With the property animation system, these restrictions are completely removed, and you can animate any property of any object (views and non-Views), and the object itself is actually modified. A real estate animation system is also more reliable in the way it is animated. At a high level, you assign animators to the properties that you want to animate, such as color, position, or size, and you can define aspects of the animation, such as interpolating and synchronizing multiple animators.

However, the viewing animation system takes less time to set up and requires less code to write. If the view animation does everything you need to do, or if your existing code already works the way you want, there is no need to use a property animation system. It may also make sense to use both animation systems for different situations if a use case arises.

http://developer.android.com/guide/topics/graphics/prop-animation.html

In my case, I used property animation, and it fits all my animation needs. Thanks for your support! :)

Floor

+4
source share

pull out set.setFillAfter(true); and use the Listener animation to set the button on the note, when the animation ends, it will give the same effect to the user, and you can make it invisible again using View.setVisibility(View.INVISIBLE);

 AnimationListener animListener; animListener = new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { btn.setVisibility(View.VISIBLE); } }; animation2.setAnimationListener(animListener); 
0
source share

All Articles