Android中轴旋转特效实现,制作别样的图片浏览器

Android API Demos中有很多非常Nice的例子,这些例子的代码都写的很出色,如果大家把API Demos中的 每个例子研究透了,那么恭喜你已经成为一个真正的Android高手了。这也算是给一些比较迷茫的Android开 发者一个指出了一个提升自我能力的方向吧。API Demos中的例子众多,今天我们就来模仿其中一个3D变换的 特效,来实现一种别样的图片浏览器。

既然是做中轴旋转的特效,那么肯定就要用到3D变换的功能。 在Android中如果想要实现3D效果一般有两种选择,一是使用Open GL ES,二是使用Camera。Open GL ES使用 起来太过复杂,一般是用于比较高级的3D特效或游戏,像比较简单的一些3D效果,使用Camera就足够了。

Camera中提供了三种旋转方法,分别是rotateX()、rotateY()和rotateZ,调用这三个方法,并传入相应 的角度,就可以让视图围绕这三个轴进行旋转,而今天我们要做的中轴旋转效果其实就是让视图围绕Y轴进行 旋转。使用Camera让视图进行旋转的示意图,如下所示:

那我们就开始动手吧,首先创 建一个Android项目,起名叫做RotatePicBrowserDemo,然后我们准备了几张图片,用于稍后在图片浏览器中 进行浏览。

而API Demos中已经给我们提供了一个非常好用的3D旋转动画的工具类Rotate3dAnimation ,这个工具类就是使用Camera来实现的,我们先将这个这个类复制到项目中来,代码如下所示:

/**
 * 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.
 */
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 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
     * @param centerY the Y center of the 3D rotation
     * @param reverse true if the translation should be reversed, false otherwise
     */
    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
    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) {
        final float fromDegrees = mFromDegrees;
        float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);  

        final float centerX = mCenterX;
        final float centerY = mCenterY;
        final Camera camera = mCamera;  

        final Matrix 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);
    }
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索private
, final
, float
, camera
, android camera
, applytransformation
, rotation
, camera视频api21android
, demo效果解决android
, t on android
, android camera
, The
, android图片旋转
android图片变换
中轴旋转门、家用中轴旋转门、中轴旋转窗、unity 3d模型中轴旋转、ps图片绕中轴立体旋转,以便于您获取更多的相关知识。

时间: 2024-08-09 04:10:00

Android中轴旋转特效实现,制作别样的图片浏览器的相关文章

用Flash制作简易的图片浏览器

浏览器 通过脚本控制,Flash可以完成许多事.本例将教大家如何使用Flash制作简易的图片浏览器. 点击这里下载源文件 1.新建一个Flash文档,单击"属性"面板中的"尺寸"按钮,打开"文档属性"面板设置场景大小为650px x 450px,背景为白色,帧频为30fps 2.按快捷键Ctrl+R打开"导入"面板导入三张图片.如图1所示,图片image的宽.高为640px.480px.把图片image的宽.高放大为2400p

【Android开发】范例2-实现幻灯片式图片浏览器

我们来实现一个幻灯片式图片浏览器: 最下面一个画廊视图,选中画廊中的图片,会在上面的ImageSwitcher控件中显示大图. 效果图如图 实现方法: 在布局文件中添加图片切换控件ImageSwitcher和画廊视图控件Gallery res/layout/main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas

Flash教程实例:如何制作别样的绿

  设置影片属性;使用"文字工具"写入文字;使用帧动作设置动作;使用帧属性设置帧的属性;创建新元件.本文对Flash教程实例 :如何制作别样的绿进行了具体阐述供阅读. [步骤] (1) 启动Flash MX 2004,如果"属性"面板没有打开,可选择菜单栏中的"窗口"|"属性"命令打开它.在"属性"面板中,设置动画尺寸大小为600×300px.确认 "帧频"文本框中的数值为12.&quo

浅谈角色旋转动画的制作

旋转 浅谈角色旋转动画的制作

Android编程之阴影(Shadow)制作方法_Android

本文实例讲述了Android编程之阴影(Shadow)制作方法.分享给大家供大家参考,具体如下: 先看运行效果图如下: 阴影制作:包括各种形状(矩形,圆形等等),以及文字等等都能设置阴影. 阴影制作是什么原理呢? 其实很简单,你需要设置阴影的东西被看作一个主层.然后在主层下面画一个阴影层. 阴影制作涉及到一个重要函数: public void setShadowLayer (float radius, float dx, float dy, int color) 参数: radius:阴影半径

flash图片_旋转特效

flash图片_旋转特效 function gttEnterFrame() {         this.xx += xspeed;         this._x = a*Math.sin(this.xx)+250;         this._xscale = a*Math.cos(this.xx);         this._yscale = 100+10*Math.cos(this.xx);         if (this._xscale>0) {                 t

图片-android一个简单动画的制作问题

问题描述 android一个简单动画的制作问题 我有一个Button,本来是这个样子,我想当按下的时候这三个样子轮流变化: 当再按下的时候变回原来的,也就是第一张的样子 怎么实现? 解决方案 制作一个简单的动画 解决方案二: j亲爱的发噶盛大而搁浅

android opengl 旋转问题

问题描述 android opengl 旋转问题 表示以前从未接触过opengl...Android camera视频用opengl 渲染时怎么对其进行90度旋转呢? 解决方案 MFC中OpenGL旋转的问题Android 屏幕旋转问题Android OpenGL之二图像旋转实例

动画效果-android 一个旋转动画的效果,未完全展示

问题描述 android 一个旋转动画的效果,未完全展示 ndroid,我对一个按钮button做点击事件,点击button后将一张图片旋转90度,但是频繁点击的过程中,总会有几次图片没有旋转到90度,或者压根就没有旋转. 我在旋转动画的监听onAnimationEnd()方法里面,输出了debug,代码确实执行到这里了,为什么执行动画后,页面效果看不见. 请有经验和知道状况的朋友,指导下,谢谢 解决方案 最好用属性动画做,如果是需要完整执行每个点击响应就每次都起个线程post到ui进程来做动画