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

@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;
    }
}

布局:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值