属性动画(旋转、平移、缩放、透明、综合)

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_rotate://360度旋转
            ObjectAnimator rotate = ObjectAnimator.ofFloat(img, "rotation", 0f, 360f);
            rotate.setDuration(2500);//时间
            rotate.setRepeatCount(3);//次数+1
            rotate.start();//开始

            break;
        case R.id.btn_translation://平移
            //将TextView先向右,然后再移动回来   -500f是向左移动
           /* float dis = img.getTranslationX();
            ObjectAnimator translation = ObjectAnimator.ofFloat(img, "translationX",  dis,500f,dis);*/
            //将img先向右移动  不回来
            ObjectAnimator translation = ObjectAnimator.ofFloat(img, "translationX",  500f);
            translation.setDuration(2500);
            translation.start();
            break;
        case R.id.btn_zoom://缩放
            ObjectAnimator zoom = ObjectAnimator.ofFloat(img, "scaleX", 1f, 3f, 1f);
            zoom.setDuration(2500);
            zoom.start();

            break;
        case R.id.btn_transparent://透明
            ObjectAnimator transparent = ObjectAnimator.ofFloat(img, "alpha", 1f, 0f, 1f);
            transparent.setDuration(2500);
            transparent.start();
            break;
        case R.id.btn_comprehensive://综合
            ObjectAnimator move = ObjectAnimator.ofFloat(img, "translationX",  500f);
            ObjectAnimator rotate1 = ObjectAnimator.ofFloat(img, "rotation", 0f, 360f);
            ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 1f, 0f, 1f);

            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playSequentially(rotate1,move,alpha);
            animatorSet.setDuration(5000);
            animatorSet.start();
            break;
    }
}

布局:

属性动画(旋转、平移、缩放、透明、综合)_第1张图片

你可能感兴趣的:(属性动画(旋转、平移、缩放、透明、综合))