Android属性动画(三):AnimationSet 和 animate()

1、虽然PropertyValuesHolder可以对多个属性进行操作, 而AnimatorSet 类似视图动画,还可以设置多个属性的发生顺序等等:

如: 

ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(View,"translationX", 150);
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(View,"alpha", 0.5f);
ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(View,"y", 100);
AnimatorSet set = new AnimatorSet();
set.setDuration(1000); 
set.playSequentially(objectAnimator,objectAnimator2,objectAnimator3);//animators依次执行
set.playTogether(objectAnimator,objectAnimator2,objectAnimator3); //animators同时执行
set.setStartDelay(500); //在start()后delay
set.start();

AnimatorSet 还有别的功能,详情见API啦

2、 view自身的animate()方法:

如:

view.animate().scaleX(1).alpha(0.5f).setDuration(1000).withStartAction(new Runnable() {
    @Override
    public void run() {
        runOnUiThread(new Runnable() { //用以在UI线程上执行,效果类似Handler
            @Override
            public void run() {
            }
        });
    }
}).withEndAction(new Runnable() {
    @Override
    public void run() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
    }
}).start();

3、xml加载动画:

新建一个animator类型的xml:


代码类似在java中的代码,使用时:

Animator animator = AnimatorInflater.loadAnimator(this, R.animator.scaleX);

animator.setTarget(view);

animator.start();

 

晚安~orz

你可能感兴趣的:(Android群英传学习笔记)