Android 点击View Rotate旋转带视图动画

这篇博客介绍了如何在Android中实现点击View时进行Rotate旋转的视图动画,包括500毫秒的切换动画效果。在初始化和恢复状态时,通过设置durationMillis为0来消除动画。视图动画不会改变View的原始属性,提供了一个简单快速的实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述
关闭状态

这里写图片描述
打开状态

切换有500秒动画

初始化恢复打开关闭状态时,动画durationMillis设置为0

   private void rotateOpen(final View v,long durationMillis) {

        AnimationSet animationSet = new AnimationSet(true);
        /**
         *  //参数1:从哪个旋转角度开始

         //参数2:转到什么角度

         //后4个参数用于设置围绕着旋转的圆的圆心在哪里

         //参数3:确定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标

         //参数4:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴

         //参数5:确定y轴坐标的类型

         //参数6:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴
         */

        RotateAnimation animation = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(durationMillis);//设置动画持续时间
/** 常用方法 */
        //animation.setRepeatCount(0);//设置重复次数
        //animation.setStartOffset(long startOffset);//执行前的等待时间
        //animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态
        animationSet.addAnimation(animation);
        animationSet.setFillAfter(true);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // v.clearAnimation();

                // v.setRotation(180f);


            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        // v.setAnimation(animation);
        // animation.startNow();
        v.startAnimation(animationSet);
    }
  private void rotateClose(final View v,long durationMillis) {
        //
        AnimationSet animationSet = new AnimationSet(true);
        //参数1:从哪个旋转角度开始

         //参数2:转到什么角度

         //后4个参数用于设置围绕着旋转的圆的圆心在哪里

         //参数3:确定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标

         //参数4:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴

         //参数5:确定y轴坐标的类型

         //参数6:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴
        RotateAnimation animation = new RotateAnimation(180f, 360f, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(durationMillis);//设置动画持续时间

        //animation.setRepeatCount(0);//设置重复次数
        //animation.setStartOffset(long startOffset);//执行前的等待时间
        //animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态
        animationSet.addAnimation(animation);
        animationSet.setFillAfter(true);
        // v.setAnimation(animation);
        // animation.startNow();
        v.startAnimation(animationSet);
    }

视图动画只改变样子不改变原有属性,所以比较长。。。

简单快速实现见:

Android 点击View Rotate旋转带视图动画
http://blog.youkuaiyun.com/RichieZhu/article/details/52201679

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值