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. [白话解析] 通俗解析集成学习之bagging,boosting & 随机森林

    本文将尽量使用通俗易懂的方式,尽可能不涉及数学公式,而是从整体的思路上来看,运用感性直觉的思考来解释 集成学习 […]...

  2. 使用Aspose.Words组件给word加水印 – 大唐高僧

    使用Aspose.Words组件给word加水印 使用Aspose.Words组件给word加水印 /// & […]...

  3. 扩展名大全 – 非常+++

    扩展名大全 转自:http://www.loveyuki.com/blogview.asp?logID=687 […]...

  4. 在线免费pdf转word – DiligentCoder

    在线免费pdf转word http://www.pdfdo.com/pdf-to-word.aspx...

  5. 像素 分辨率 dpi – daition

    像素 分辨率 dpi zz  [url]http://zhidao.baidu.com/question/21 […]...

  6. 使用ActivityGroup需要注意的地方 – java豆子

    使用ActivityGroup需要注意的地方         Group里面的所有“孩子Activity”不能 […]...

  7. Android 应用程序集成Google 登录及二次封装 – Sun‘刺眼的博客

    Android 应用程序集成Google 登录及二次封装 谷歌登录API:  https://develope […]...

  8. mysql 压力测试工具 – 很多不懂呀。。

    mysql 压力测试工具 MySQL5.1地的确提供了好多有力的工具来帮助我们DBA进行数据库管理。现在看一下 […]...

随机推荐

  1. MySQL高级

    MySQL高级 一,myslq 的架构介绍 1.1 mysql 简介 1.1.1 概述: MySQL 是一个关 […]...

  2. 【曹工杂谈】Maven底层容器Plexus Container的前世今生,一代芳华终落幕

    Maven底层容器Plexus Container的前世今生,一代芳华终落幕 前言 说实话,我非常地纠结,大家 […]...

  3. C# 发送HTTP请求超时解决办法

    request.GetResponse();超时问题的解决,和HttpWebRequest多线程性能问题,请求 […]...

  4. Java实现加密和解密的源代码

    本文转载于网络,抄录下来只是为了方便以后查找。原文地址:http://snowolf.iteye.com/bl […]...

  5. MySQL 5.7 安装教程(Win 10)

    MySQL5.7 下载 官网下载(不推荐使用):https://dev.mysql.com/downloads […]...

  6. Android开发之蓝牙(Bluetooth)操作(一)–扫描已经配对的蓝牙设备

    版权声明:本文为博主原创文章,未经博主允许不得转载。 一. 什么是蓝牙(Bluetooth)?   1.1   […]...

  7. 二进制的位运算

    二进制的位运算: 1、按位与 & 1)清零。如果想将一个单元清零,即使其全部二进制位为0,只要与一个各 […]...

  8. python3+dlib人脸识别及情绪分析

    在dlib人脸识别的基础上进行对人表情的识别。 一、介绍 我想做的是基于人脸识别的表情(情绪)分析。看到网上也 […]...

展开目录

目录导航