android 动画x轴旋转,Android Roate3dAnimation实现围绕y轴竖直方向或者绕x轴方向旋转的3d动画效果...
概要:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Roate3dAnimation 实现了围绕y轴竖直方向 或者绕x轴方向旋转的3d动画效果。这个例子来
自Android APIDemo中的一个自定义View动画。他的实现展示自定义View动画的基本步骤。
主要是重写initialize方法,applyTransformation方法。
分析:
在Roate3dAnimation中,我们使用Android.graphic.Camera实现3d效果。
对Camera不熟悉的可看看 android.graphic.Camera 。
public class Rotate3dAnimation extends Animation {
//开始角度
private float startDegree;
//结束角度
private float endDegree;
/**
* 这个旋转动画围绕在2D空间的中心点执行.你可以用X轴坐标(叫做centerX)和Y轴(叫做centerY)
* 坐标来定义这个中心点
*/
private float centerX;
private float centerY;
/**
* 控制镜头景深,不需要的话给0值即可
* mReverse 为true,表示反方向,false 表示正方向
*/
private float deepZ;
private boolean mReverse;
//用于辅助实现3d效果。
private Camera mCamera;
//X轴方向,或Y轴方向
enum DIRECTION {
X, Y
}
DIRECTION direction = DIRECTION.Y;
Rotate3dAnimation(float fromDegree, float toDegree, float centerX,
float centerY, float deepZ, boolean reverse) {
this.startDegree = fromDegree;
this.endDegree = toDegree;
this.centerX = centerX;
this.centerY = centerY;
this.deepZ = deepZ;
this.mReverse = reverse;
}
Rotate3dAnimation(float fromDegree, float toDegree, float centerX,
float centerY, float deepZ, boolean reverse, DIRECTION direction) {
this.startDegree = fromDegree;
this.endDegree = toDegree;
this.centerX = centerX;
this.centerY = centerY;
this.deepZ = deepZ;
this.mReverse = reverse;
this.direction = direction;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
float fromDegree = startDegree;
float degree = fromDegree + (endDegree - startDegree) * interpolatedTime;
final Matrix matrix = t.getMatrix();
mCamera.save();
if (mReverse) {
mCamera.translate(0, 0, deepZ * interpolatedTime);
} else {
mCamera.translate(0, 0, deepZ * (1 - interpolatedTime));
}
if (direction == DIRECTION.Y) {
mCamera.rotateY(degree);
} else {
mCamera.rotateX(degree);
}
mCamera.getMatrix(matrix);
mCamera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
应用:
iv_content.post(new Runnable() {
@Override
public void run() {
Rotate3dAnimation rotate3dAnimation = new Rotate3dAnimation(0, 360, iv_content.getWidth()/2,
0, 0, true, Rotate3dAnimation.DIRECTION.Y);
rotate3dAnimation.setDuration(3000);
iv_content.setAnimation(rotate3dAnimation);
rotate3dAnimation.start();
}
});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
小奋斗文章
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
android 动画x轴旋转,Android Roate3dAnimation实现围绕y轴竖直方向或者绕x轴方向旋转的3d动画效果...相关推荐
- python绘制多条不同x轴曲线_Python matplotlib 绘制双Y轴曲线图的示例代码
Matplotlib简介 Matplotlib是非常强大的python画图工具 Matplotlib可以画图线图.散点图.等高线图.条形图.柱形图.3D图形.图形动画等. Matplotlib安装 p ...
- R语言使用latticeExtra包可视化双Y轴线图实战(Dual Y axis):单y轴线图、双y轴图线图、双y轴图线图(添加图例)
R语言使用latticeExtra包可视化双Y轴线图实战(Dual Y axis):单y轴线图.双y轴图线图.双y轴图线图(添加图例) 目录
- 双y轴设置 颜色_项目实战:Qt多段Y轴折线图框架(双Y轴段折线、支持拽拖、浮动游标显示X值各段Y值、实时下位机数据)...
若该文为原创文章,转载请注明原文出处 本文章博客地址:https://blog.csdn.net/qq21497936/article/details/111660400长期持续带来更多项目与技术分享 ...
- matlab 为双y轴加标签,[转载]matlab双y轴添加误差棒(转载)
matlab的双y轴网上有很多方法,但是带置信区间的双y轴就很少了,并且由于网上给的例子一般都是使用红蓝两色,对于只想使用黑色或者灰色的俺们来说太鲜艳啦~ 上图为使用matlab绘制的双y轴带置信区间 ...
- java作图哪个是x轴_java – 主要以X和Y轴绘制的圆圈,为什么?
我使用绘制圆的处理创建了一个循环,整体形状应该是一个圆.然而,它们主要靠近X和Y轴绘制.我已经随机化了它的位置微积分的角度,我看不出问题出在哪里. 代码如下: for (int omega = 0; ...
- ECharts Y轴固定分割段数,Y轴动态数值非写死
网上一些方法是写死最大值最小值和步长, 我这里最大值不确定需要动态设置,使用以下方法. //计算ehcarts y轴最大值 和 步长 let maxVal = 0; //最大值 let intVal ...
- origin如何绘制双y轴曲线_origin怎么画双y轴 看完恍然大悟
在平时数据处理过程中,常常需要做双Y轴的曲线图.Origin作为一款功能强大的绘图软件,可以轻松地作出漂亮的双y轴曲线图.那么具体的操作是怎样的呢?下面就和大家详细地分享一下利用Origin软件绘制双 ...
- origin如何绘制双y轴曲线_origin怎样画双y轴 看完恍然大悟
软件安装:装机软件必备包 关于电脑装机必须的软件,比如windows office系列办公软件.网页浏览器.杀毒软件.安全防护软件.刻录软件.压缩软件.下载工具.多媒体播放软件.多媒体编辑软件.输入法 ...
- python怎么定义y轴_在matplotlib中设置y轴限制
我需要帮助设置matplotlib上的y轴限制.这是我尝试过的代码,但没有成功. import matplotlib.pyplot as plt plt.figure(1, figsize = (8. ...
最新文章
- activemq 连接mysql_ActiveMQ 内存配置,ActiveMQ 和mysql
- DNS隧道工具dns2tcp
- matlab在命令行注册,命令行运行matlab
- Android8.0适配那点事(二)
- python和javascript哪个好_JavaScript与Python:主要区别
- VTK:Filtering之Glyph2D
- win7右键点击文件夹进入命令窗口方法
- StackOverflow
- 网页版Facebook第三方登陆
- Python打包为exe文件
- Linux man帮助文档
- VBA--遍历所有工作表,获取所有行和列,复制粘贴为数值
- Android中关于ComponentName的使用
- IDEA的ultimate(最终版)与community(社区版)的区别?
- 基于改进鲸鱼优化算法的WSN覆盖优化
- bodipy荧光染料BDP R6G maleimide/马来酰亚胺,CAS:2183473-32-5
- 国产全新 OS 惊艳老外!界面似 Win11,可运行多应用
- java.lang.NoClassDefFoundError: javax/activation/DataSource
- 单细胞免疫组库揭示肿瘤免疫疗法副作用的分子机制
- 实验一 视频/图像信号处理实验