demand:
1. The vertical position of the layer in accordance with the layout of a fixed time interval transparency change animation playback
2. When playback zoom animation playback transparency
4. When the zoom animation execution is complete transparency have all become opaque 1
Results are as follows:
The principle analysis:
1. Prior to the layout according to the layout on to the next level
2. For each layer added a transparency gradient animation
3. The delay time in accordance with the increase on to the next level of play
4. Add the entire layout of a zoom animation, when the first animated feature to try to change transparency from the beginning to the end of the last
Code:
A combination of animation we must first think of AnimatorSet, the object can be any combination of animation
For example, the animation is provided a AnimatorSet 1 and 2 while playing movie, animation 3 animation play after 2, 4 play the animation after the end of the animation 3:
AnimatorSet s = new AnimatorSet();
s.play(anim1).with(anim2);
s.play(anim2).before(anim3);
s.play(anim4).after(anim3);
//顺序播放
set.playSequentially(anim1, anim2, anim3);
But we realize the effect is not so on the next one will be executed after the implementation of a complete, but before executing another one will be executed in a period of time, in which case we need to know each animation execution time interval, in every animation make a delayed execution time execution.
Final code to achieve the following:
public AnimatorSet animatorAlpha(float startAlpha , float targetAlpha){
AnimatorSet set = LauncherAnimUtils.createAnimatorSet();
//所有View按顺序加入List列表
Iterator<View> iterator = animationDisplayOdeer.iterator();
int time = ALPHA_ANIMATION_DELAY_TIME;
//先将每一层View透明度设为0
while (iterator.hasNext()){
View view = iterator.next();
if(view != null && view.getVisibility() == VISIBLE){
view.setAlpha(0);
}
}
iterator = animationDisplayOdeer.iterator();
//给每一个View添加一个透明度动画
while (iterator.hasNext()){
View view = iterator.next();
if(view != null && view.getVisibility() == VISIBLE){
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", startAlpha , targetAlpha);
ObjectAnimator oa =
LauncherAnimUtils.ofPropertyValuesHolder(view, alpha);
play(set, oa, time, OVER_DISAPLAY_ANIMATIO_NDRUATION);
//累加时间间隔
time +=ALPHA_ANIMATION_DELAY_TIME;
}
}
//给整个View添加一个缩放动画
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", OVER_DISAPLAY_START_SCALE , OVER_DISAPLAY_END_SCALE);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", OVER_DISAPLAY_START_SCALE , OVER_DISAPLAY_END_SCALE);
final ObjectAnimator oa =
LauncherAnimUtils.ofPropertyValuesHolder(this,scaleX, scaleY);
//缩放动画时间
play(set, oa, 0, time);
return set;
}
//将动画添加到AnimatorSet 中
private void play(AnimatorSet as, Animator a, long startDelay, int duration) {
a.setStartDelay(startDelay);
a.setDuration(duration);
as.play(a);
}
to sum up:
Each View can add a separate animation and set the time and setDuration setStartDelay time and by play (a) added to the animation, can not give here
AnimatorSet set the time.