繁体   English   中英

Android:如何制作Android活动的翻转动画,就像iphone从左到右水平翻转?

[英]Android: How to make the flip animation for android activity, as like iphone flip horizontal from left to right?

在我的应用程序中,我想翻转视图..我在iPhone中看过这样的动画。 同样的事情,我想要我的Android应用程序。

我想翻转整个活动视图。 可能吗 ? 我在android中看到了翻转的一些例子。 但是在所有示例中,视图都在同一个活动中。 是否可以为不同的活动设置此类视图。 或者从一个活动到另一个活动时做这样的效果?

请参阅iPhone中的翻转效果快照:

在此输入图像描述

如果是,那么请参考任何演示示例或代码。 谢谢。

首先定义自己的动画,然后将其存储在res-> anim或java类下的XML中。 除了在Eclipse中附带SDK下载的API Demos之外,我没有任何工作示例,如果您正在寻找翻转动画,请尝试查看3D Transition类。

之后有你的活动加载那个动画,最好把它加载到onCreate。 请参考这个问题

您可以使用这些xml文件非常相似。

rotate_out.xml

<?xml version="1.0" encoding="utf-8"?>

<scale
    android:duration="300"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.0"
    android:toYScale="0.90" />

<alpha
    android:duration="1"
    android:fromAlpha="1.0"
    android:startOffset="500"
    android:toAlpha="0.0" />

rotate_in.xml

<?xml version="1.0" encoding="utf-8"?>

<scale
    android:duration="200"
    android:fromXScale="0.0"
    android:fromYScale="0.90"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="500"
    android:toXScale="1.0"
    android:toYScale="1.0" />

<alpha
    android:duration="1"
    android:fromAlpha="0.0"
    android:startOffset="500"
    android:toAlpha="1.0" />

然后在startActivity()或finish()之后的代码覆盖转换中:

overridePendingTransition(R.anim.rotate_in, R.anim.rotate_out);

我见过的最令人信服的3D翻转动画之一是在这里完成的https://code.google.com/p/android-3d-flip-view-transition

许多其他教程和示例代码不会产生可信的3D翻转。 在y轴上的简单旋转不是在iOS中完成的。

这里还有一个视频:http: //youtu.be/52mXHqX9f3Y

在iOS肖像: 旋转到中间ios

“许多其他教程和示例代码都不会产生可信的3D翻转。 在y轴上的简单旋转不是在iOS中完成的。 ”在将近30小时搜索样本后,我必须同意。 我有一部电影,我可以在中间截取屏幕截图。 视图的右侧有: - 向左移动,缩小到95%。 视图的左侧有: - 向右侧移动,缩小到80%。

在Android Full(初始状态): android初始

Android中间: android中间

Android代码:

// @param interpolatedTime The value of the normalized time (0.0 to 1.0)
// @param t The Transformation object to fill in with the current transforms.
protected void applyTransformation(float interpolatedTime, Transformation t){

    float degrees = toDegree*interpolatedTime;
    //float rad = (float) (degrees * Math.PI / 180.0f);

    Matrix matrix = t.getMatrix();
    camera.save();

    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);// M' = M * T(dx, dy)
    matrix.postTranslate(centerX, centerY); // M' = T(dx, dy) * M
}

在大多数示例中可以找到代码的改进版本:

    // @param interpolatedTime The value of the normalized time (0.0 to 1.0)
    // @param t The Transformation object to fill in with the current transforms.
    protected void applyTransformation(float interpolatedTime, Transformation t){

        float degrees = toDegree*interpolatedTime;
        //float rad = (float) (degrees * Math.PI / 180.0f);

        Matrix matrix = t.getMatrix();
        camera.save();

        camera.translate(0.0f, 0.0f, mDepthZ *  interpolatedTime);
        camera.rotateY(degrees);

        camera.getMatrix(matrix);
        camera.restore();

        matrix.preTranslate(-centerX, -centerY);// M' = M * T(dx, dy)
        matrix.postTranslate(centerX, centerY); // M' = T(dx, dy) * M
    }

改进了android

一些区别是: - 视图的右侧不像iOS那样移动。

这是Android Camera轴: 轴

我确实相信Z轴上的转换不能解决它。 也许某种程度上需要缩小。

float dz = (float) (centerX *  Math.sin(rad));
camera.translate(0f, 0f, -dz);

仍然不够。 左侧收缩很多。

ž

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM