属性动画实现

来源:互联网 发布:电脑部分软件乱码 编辑:程序博客网 时间:2024/06/06 12:20
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();    }}
原创粉丝点击