//属性动画(text1是你要想动的View
float translationX = text1.getTranslationX();
//获得当前按钮的位置
ObjectAnimator animator = ObjectAnimator.ofFloat(text1, "translationX", 300, translationX);
//放大
ObjectAnimator scaleX = ObjectAnimator.ofFloat(text1, "scaleX", 1f, 3f, 1f);
//透明
ObjectAnimator alpha = ObjectAnimator.ofFloat(text1, "alpha", 1f, 0f, 1f);
//旋转
ObjectAnimator rotation = ObjectAnimator.ofFloat(text1, "rotation", 0f, 360f);
//背景渐变颜色
ObjectAnimator backgroundColor = ObjectAnimator.ofInt(text1, "backgroundColor", 0x00FFFFFF , 0x6600ff00);
//不加它的话是闪光灯效果一样(在这里不加了
//backgroundColor.setEvaluator(new ArgbEvaluator());
//组合动画
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(animator).with(scaleX).with(alpha).with(rotation).before(backgroundColor);
animatorSet.setDuration(5000);
animatorSet.start();
//动画监听
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Toast.makeText(Main2Activity.this,"动画结束",Toast.LENGTH_LONG).show();
}
});
}
Android简单明了的使用属性动画ObjectAnimator 旋转 平移 渐变 缩放 透明监听事件
猜你喜欢
转载自blog.csdn.net/Android_Mr_Zhao/article/details/89554637
今日推荐
周排行