Socket two animations in android

I would like to implement alpha animation when I click one of the buttons.

Animation: Alpha down from 1 to 0.5 and when it reaches 0.5 back from 0.5 to 1. Cycling and animation. How can I do it? Can I define it in an xml file in the /res/anim folder or do I need to use AnimationListener ?

thanks

+4
source share
2 answers

You can use a simple AlphaAnimation object for AlphaAnimation . Set the repeat mode to setRepeatMode(Animation.REVERSE) to change alpha from 0.5 to 1.0 and setRepeatCount(count) to repeat several times.

xml animation sample:

 <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="1.0" android:toAlpha="0.5" android:duration="1000" /> 

code to download xml:

 Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha); a.reset(); a.setRepeatMode(Animation.REVERSE); a.setRepeatCount(5); // will be infinite if -1 Button btn = (Button ) findViewById(R.id.btn); btn.clearAnimation(); btn.startAnimation(a); 

The code is just a sample. Hope this works.

+4
source

I did something like this using AnimationListeners . Fill the animation and then call them in each other AnimationListener onAnimationEnd() . I can’t say if this is the only way to achieve the effect, but nonetheless it works.

+1
source

All Articles