实现View 3D翻转效果

这篇博客介绍了两种实现View 3D翻转效果的方法。第一种利用原生RotateAnimation和Matrix视图变换,通过Camera操作实现3D旋转,并创建自定义布局控制动画。第二种方法采用属性动画,结合Matrix矩阵变换,实现更流畅的3D翻转效果。

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

原生RotateAnimation

原生RotateAnimation 只能是平面的旋转,实现不了3D效果。


        RotateAnimation rotateAnimation = new RotateAnimation(0f, 359f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(2000);
        rotateAnimation.setInterpolator(new LinearInterpolator());
        rotateAnimation.setFillAfter(true);
        rotateAnimation.setRepeatCount(-1);
        //rotateAnimation.setRepeatMode(ValueAnimator.REVERSE);
        rotateAnimation.setRepeatMode(ValueAnimator.RESTART);
//        mDefaultLayout.setAnimation(rotateAnimation);
        mDefaultLayout.startAnimation(rotateAnimation);
        

Matrix视图变换

1 自定义的Animation 重写 applyTransformation(float interpolatedTime, Transformation t) 方法
interpolatedTime : 因子 0 - > 1
2 主要是通过对android.graphics.Camera的操作来实现3D的变化效果。

  1. 要旋转的布局沿Y轴旋
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值