java图形旋转动画_Android使用Rotate3dAnimation实现3D旋转动画效果的实例代码

本文介绍了如何在Android中使用Rotate3dAnimation实现3D旋转动画,通过创建并应用相机(Camera)进行图像旋转,详细展示了相关代码实现,包括旋转角度、中心点和Z轴缩放的设置,以及动画监听器的使用。
摘要由CSDN通过智能技术生成

Android使用Rotate3dAnimation实现3D旋转动画效果的实例代码

发布时间:2020-09-09 00:22:18

来源:脚本之家

阅读:209

作者:寒江蓑笠

利用Android的ApiDemos的Rotate3dAnimation实现了个图片3D旋转的动画,围绕Y轴进行旋转,还可以实现Z轴的缩放。点击开始按钮开始旋转,点击结束按钮停止旋转。

db19a21e648cfd80fe6fe564b739b533.png

4a2f7d886e7b9c4b85e8cd5750dc78d0.png

代码如下::

Rotate3dAnimation.java

public class Rotate3dAnimation extends Animation {

private final float mFromDegrees;

private final float mToDegrees;

private final float mCenterX;

private final float mCenterY;

private final float mDepthZ;

private final boolean mReverse;

private Camera mCamera;

/**

* Creates a new 3D rotation on the Y axis. The rotation is defined by its

* start angle and its end angle. Both angles are in degrees. The rotation

* is performed around a center point on the 2D space, definied by a pair

* of X and Y coordinates, called centerX and centerY. When the animation

* starts, a translation on the Z axis (depth) is performed. The length

* of the translation can be specified, as well as whether the translation

* should be reversed in time.

*

* @param fromD

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于谷歌官方提供的3D翻转示例进行修改,修复了在不同设备上显示效果差异过大的问题。项目地址:https://github.com/GcsSloop/Rotate3dAnimation 效果图:如何使用:// 计算中心点(这里是使用view的中心作为旋转的中心点)         final float centerX = view.getWidth() / 2.0f;                 final float centerY = view.getHeight() / 2.0f;        //括号内参数分别为(上下文,开始角度,结束角度,x轴中心点,y轴中心点,深度,是否扭曲)         final Rotate3dAnimation rotation = new Rotate3dAnimation(this, start, end, centerX, centerY, 1.0f, true);         rotation.setDuration(1500);                               //设置动画时长         rotation.setFillAfter(true);                              //保持旋转效果         rotation.setInterpolator(new AccelerateInterpolator());   //设置插值器         rotation.setAnimationListener(new AnimationListener() {   //设置监听器             @Override             public void onAnimationStart(Animation animation) {             }            @Override             public void onAnimationRepeat(Animation animation) {             }            @Override             public void onAnimationEnd(Animation animation) {             }         });         view.startAnimation(rotation);                            //开始动画
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值