I want to do a very simple alpha animation but I cannot find a valid way.
The idea is to perform this animation over a view:
- alpha from 0 to 1 of 1 second
- hold alpha at 1 for 5 seconds
- alpha from 1 to 0 of 1 second
- hold alpha at 0 for 5 seconds.
- start again on 1.
I’ve tried to implement that with an AnimationSet as:
AnimationSet animationSet = new AnimationSet(true);
Animation animation1 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
animation1.setDuration(1000);
Animation animation2 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
animation2.setDuration(1000);
animation2.setStartOffset(5000);
Animation animation3 = new AlphaAnimation(0.0f, 0.0f);
animation3.setDuration(4000)
animation3.setStartOffset(6000);
animationSet.add(animation1);
animationSet.add(animation2);
animationSet.add(animation3);
etc..
but it seams that the third animation do a mess with all the alpha animations, I supose that this cause an internal incoherence in the way that Android manage this type of animation.
Any idea?
Thank you.
Ok Keep in mind these 2 points to solve this
If I want to animate
1.0f to 0.0fafter 5 seconds with an animation duration of 1 seconds, this is ultimately a 1 second animation with a pause of 5 seconds.To acheive this:
setDuration(1000)(it has a 1 second duration)setStartOffset(5000)(it will start after 5 seconds)You only need 2 animations that will loop forever.
1.
0.0f to 1.0fwith 5 seconds pause and 1 second duration2.
1.0f to 0.0fwith 5 seconds pause and 1 second durationAnd here is the code:
However to loop forever I will use
AnimationListenerbecause repeatCount is buggy: