public class MainActivity extends AppCompatActivity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.img); } private void anim() { //透明 ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0.5f); //持续时间,无限循环 alpha.setDuration(2000).setRepeatCount(ValueAnimator.INFINITE); //回到初始位置 alpha.setRepeatMode(ValueAnimator.RESTART); alpha.start(); //旋转 ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView,"rotation",360); rotation.setDuration(2000).setRepeatCount(ValueAnimator.INFINITE); rotation.setRepeatMode(ValueAnimator.RESTART); rotation.start(); //偏移 ObjectAnimator translationX = ObjectAnimator.ofFloat(imageView,"translationX",500); translationX.setDuration(2000).setRepeatCount(ValueAnimator.INFINITE); translationX.setRepeatMode(ValueAnimator.RESTART); translationX.start(); //缩放 ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView,"scaleX",2); scaleX.setDuration(2000).setRepeatCount(ValueAnimator.INFINITE); scaleX.setRepeatMode(ValueAnimator.RESTART); scaleX.start(); //组合动画 new AnimatorSet().playSequentially(alpha,rotation,translationX,scaleX); } public void Start(View view) { anim(); } }
属性动画实现
最新推荐文章于 2019-09-22 12:37:52 发布