android 自定义动画1 Rotate3dAnimation - 老菜_

shanzei 2021-08-13 原文


android 自定义动画1 Rotate3dAnimation

android 里的2d动画有tween 和frame, 像镜面反转这种动画它内部没有提供支持, 上网查了一下.有人写了这个效果, 但是写得怎一个乱字了得, 又查了一下api demo里就有, 你们还弄什么乱七八糟的啊.http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html如下:

Rotate3dAnimation.java

The file containing the source code shown below is located in the corresponding directory in <sdk>/samples/android-<version>/...

译: 下列包含源码的文件位于相应的<sdk>/samples/android-<version>/…目录下

package com.example.android.apis.animation;

import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.graphics.Camera;
import android.graphics.Matrix;

/**
 * An animation that rotates the view on the Y axis between two specified angles.
 * This animation also adds a translation on the Z axis (depth) to improve the effect.
译: 一个在指定了两个角度的在Y轴旋转的动画类.
这个类也添加了一个z轴的属性用来提高效果.
 */

publicclassRotate3dAnimationextendsAnimation{
   
privatefinalfloat mFromDegrees;
   
privatefinalfloat mToDegrees;
   
privatefinalfloat mCenterX;
   
privatefinalfloat mCenterY;
   
privatefinalfloat mDepthZ;
   
privatefinalboolean mReverse;
   
privateCamera 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.
在Y轴创建了一个新的3D的旋转动画,这个旋转动画定义了它的开始角度和结束角度,两个角度的单位都是度数
,这个旋转动画围绕在2D空间的中心点执行.你可以用X轴坐标(叫做
centerX)和Y轴(叫做centerY)坐标来定
义这个中心点.当动画开始时,对于z轴(深度)的转换就会被执行.转换的长度和转换正向反向都可以指定.
     * @param fromDegrees the start angle of the 3D rotation 开始的角度
     * @param toDegrees the end angle of the 3D rotation 结束的角度
     * @param centerX the X center of the 3D rotation 中心点X轴坐标
     * @param centerY the Y center of the 3D rotation 中心点Y轴坐标
     * @param reverse true if the translation should be reversed, false otherwise true表示反向,false表示正向

     */

   
public Rotate3dAnimation(float fromDegrees,float toDegrees,
           
float centerX,float centerY,float depthZ,boolean reverse){
        mFromDegrees
= fromDegrees;
        mToDegrees
= toDegrees;
        mCenterX
= centerX;
        mCenterY
= centerY;
        mDepthZ
= depthZ;
        mReverse
= reverse;
   
}

   
@Override
   
publicvoid initialize(int width,int height,int parentWidth,int parentHeight){
       
super.initialize(width, height, parentWidth, parentHeight);
        mCamera
=newCamera();
   
}

   
@Override
   
protectedvoid applyTransformation(float interpolatedTime,Transformation t){
       
finalfloat fromDegrees = mFromDegrees;
       
float degrees = fromDegrees +((mToDegrees - fromDegrees)* interpolatedTime);

       
finalfloat centerX = mCenterX;
       
finalfloat centerY = mCenterY;
       
finalCamera camera = mCamera;

       
finalMatrix matrix = t.getMatrix();

        camera
.save();
       
if(mReverse){
            camera
.translate(0.0f,0.0f, mDepthZ * interpolatedTime);
       
}else{
            camera
.translate(0.0f,0.0f, mDepthZ *(1.0f- interpolatedTime));
       
}
        camera
.rotateY(degrees);
        camera
.getMatrix(matrix);
        camera
.restore();

        matrix
.preTranslate(-centerX,-centerY);
        matrix
.postTranslate(centerX, centerY);
   
}
}

http://www.cnblogs.com/olvo/archive/2012/04/25/2469218.html
发表于
2013-06-02 15:51 
老菜_ 
阅读(778
评论(0
编辑 
收藏 
举报

 

版权声明:本文为shanzei原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/shanzei/archive/2013/06/02/3113976.html

android 自定义动画1 Rotate3dAnimation - 老菜_的更多相关文章

  1. 基于51单片机的Uart串口通信协议 – 飞鸟量天高

    基于51单片机的Uart串口通信协议 1.串口通信协议   嵌入式开发中,UART串口通信协议是我们常用的通信 […]...

  2. 初识python 之 爬虫:BeautifulSoup 的 find、find_all、select 方法 – Simple-Sir

    初识python 之 爬虫:BeautifulSoup 的 find、find_all、select 方法 f […]...

  3. 终端服务器超出了最大允许连接数的解决办法(转) – 恋地高飞

    终端服务器超出了最大允许连接数的解决办法(转)   终端服务器超出了最大允许连接数的解决办法 1、首先你可以t […]...

  4. 移动开发者的自学宝典:十大在线编程学习网站 – passer1991

    移动开发者的自学宝典:十大在线编程学习网站 http://www.csdn.net/article/2013- […]...

  5. kafka参数解析 – luckyna

    kafka参数解析 一、kafka参数解析 一个消费者可以消费同一个topic的多个分区,但是一个分区不能被同 […]...

  6. 人工智能与深度学习 – 时间朋友

    人工智能与深度学习 人工智能的关键是机器学习,机器学习的突破是深度学习,人工神经网络。     1956年,在 […]...

  7. 多渠道推广场景下,如何实现 App 用户增长的精准归因? – 马蜂窝技术

    多渠道推广场景下,如何实现 App 用户增长的精准归因? 一种精准归因 HTML5、WAP 广告投放的方法。 […]...

  8. 电子书籍搜索网站 – Alliswell_WP

    电子书籍搜索网站 目录:一、图书网站;二、整合型的网站;三、文件转换器 高质量资源 目录一、图书网站二、整合型 […]...

随机推荐

  1. Java abstract类的基本使用 和 [abstract类实现]打印1000以内的所有素数并输出时间

    笔记: /** 关键字abstract ,实现抽象类,相当于给出类的大纲,子类只管继承,但抽象类不可被实例化! […]...

  2. win10系统realtek高清晰音频管理器有什么用

    我们在使用电脑的过程中,有些小伙伴会发现有一个叫做realtek高清晰音频管理器的东西,不知道它的作用是什么。 […]...

  3. 各种电脑进入BIOS快捷键

    组装机主板 品牌笔记本 品牌台式机 主板品牌 启动按键 笔记本品牌 启动按键 台式机品牌 启动按键 华硕主板 […]...

  4. SDNU_ACM_ICPC_2021_Winter_Practice_4th [个人赛]

    传送门 D – Odd Divisor 题意: 给你一个n,问你n是否至少有一个奇数因子(这里题意 […]...

  5. python 初学之账户登录

    要求: 输入用户名密码正确,提示登录成功, 输入三次密码错误,锁定账户。 开始: 使用两个文件: 密码账户文件 […]...

  6. JMeter接口&性能测试实战案例100篇

        博客已经整合到pdf,私聊微信uhz2008获取...

  7. PDF24 Creator:能创建pdf、添加水印和签名、截图的软件

    PDF24 Creator:能创建pdf、添加水印和签名、截图的软件 PDF24 Creator是一个免费的P […]...

  8. python中装饰器的原理

    装饰器这玩意挺有用,当时感觉各种绕,现在终于绕明白了,俺滴个大爷,还是要慢慢思考才能买明白各种的真谛,没事就来 […]...

展开目录

目录导航