咱们先看个原生的
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(image,"translationY",-1000,0),
ObjectAnimator.ofFloat(image,"alpha",0,1),
ObjectAnimator.ofFloat(text,"translationX",-200,0)
);
animatorSet.setInterpolator(new DescelerateInterpolator());
animatorSet.setDuration(2000);
animatorSet.addListener(new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation) {
AnimatorSet animatorSet2 = new AnimatorSet();
animatorSet2.playTogether(
ObjectAnimator.ofFloat(image,"scaleX", 1f, 0.5f, 1f),
ObjectAnimator.ofFloat(image,"scaleY", 1f, 0.5f, 1f)
);
animatorSet2.setInterpolator(new AccelerateInterpolator());
animatorSet2.setDuration(1000);
animatorSet2.start();
}
});
animatorSet.start();
很凌乱 现在我们用ViewAnimator来实现看看效果
ViewAnimator
.animate(image)
.translationY(-1000, 0)
.alpha(0,1)
.andAnimate(text)
.dp().translationX(-20, 0)
.decelerate()
.duration(2000)
.thenAnimate(image)
.scale(1f, 0.5f, 1f)
.accelerate()
.duration(1000)
.start();
就这么几行
andAnimate 代表同时进行动画
thenAnimate代表执行完下一个动画组
项目中linlayout进入 停顿加 飞走的动画 可以参考下
thenAnimate代表执行完下一个动画组
ViewAnimator.animate(ll_fans_join_msg)
.alpha(0, 1)
.translationX(ll_fans_join_msg.getWidth(), 0)
.descelerate()//减速
.duration(300)
.thenAnimate(ll_fans_join_msg)
.alpha(1, 1)
.translationX(-ll_fans_join_msg.getHeight())
.descelerate()//减速
.duration(1250)
.thenAnimate(ll_fans_join_msg)
.alpha(1, 0)
.translationX(-1.2f * ll_fans_join_msg.getWidth())
.accelerate()//加速
.duration(250)
.onStop(new AnimationListener.Stop() {
@Override
public void onStop() {
TCSimpleUserInfo userInfo = null;
try {
userInfo = fansJoinList.remove(0);
} catch (Exception e) {
}
if (userInfo != null) {
showFansJoin(userInfo,false);
} else {
isFansJoinShowing = false;
}
}
})
/*.startDelay(2000)*/
.start();
总体来说很方便能满足绝大多数需求
磊磊tua