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

发布于 2024-12-20 21:45:49 字数 307 浏览 2 评论 0原文

在我的应用程序中,我想翻转视图.. 我在iPhone上看过这样的动画。我想在我的 Android 应用程序中实现同样的功能。

我想翻转整个活动视图。是否可以 ? 我见过一些 android 中翻转的例子。但在所有示例中,视图都位于同一个活动中。是否可以为不同的活动设置这样的视图。或者从一项活动转到另一项活动时达到这样的效果?

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

在此处输入图像描述

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

In My application i want to flip the view..
I have seen such animation in iPhone. And Same thing i want in to my android application.

I want to flip the whole activity view. is it possible ?
I have seen some example for the flip in android. But in that all example the view is in the same activity. Is it possible to set such view for the different activity. or to do such effect while going from one activity to another ?

Please see the snap for the Flip effect in iPhone:

enter image description here

If Yes then please give reference to any demo example or code.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

您的好友蓝忘机已上羡 2024-12-27 21:45:49

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

之后让您的活动加载该动画,最好在 onCreate 中加载它。请参阅此问题

Firstly define your own animation and either store it in XML under res->anim or java class. I don't have any working example other than API Demos that comes with the SDK download in Eclipse, if you're looking for a flipping animation try to look at 3D Transition class.

After that have your activity to load that animation, preferably load it in onCreate. Please refer to this question

靖瑶 2024-12-27 21:45:49

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

许多其他教程和示例代码不会产生可信的 3D 翻转。在 y 轴上进行简单的旋转并不是 iOS 中所做的事情。

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

One of the most convincing 3D flip animations for Android I've seen is done here https://code.google.com/p/android-3d-flip-view-transition.

A lot of the other tutorials and sample codes don't produce believable 3D flips. A simple rotation on the y-axis isn't what's done in iOS.

There is also a video here: http://youtu.be/52mXHqX9f3Y

你与清晨阳光 2024-12-27 21:45:49

您可以使用这些 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);

You can make a very similar with these xml files.

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" />

Then in your code override transition after startActivity() or finish():

overridePendingTransition(R.anim.rotate_in, R.anim.rotate_out);
长梦不多时 2024-12-27 21:45:49

iOS 肖像:
旋转到middle ios

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

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

Android 中:
android middle

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
    }

<图像src="https://i.sstatic.net/UJ2eY.png" alt="improved android">

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

这是 Android 相机轴:
axes

我确实相信 Z 轴上的平移不能解决这个问题。也许不知何故也需要心理医生。

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

还是不够。太多的是左侧的收缩。

z

At iOS portrait:
Rotation to middle ios

"A lot of the other tutorials and sample codes don't produce believable 3D flips. A simple rotation on the y-axis isn't what's done in iOS."
After almost 30h searching for samples I have to agree.
I have a movie, where I could take a screenshot at the middle.
The right side of the view has:
- a movement to left AND a shrink to 95%.
The left side of the view has:
- a movement to right side AND a shrink to 80%.

At Android Full ( initial state):
android initial

Android middle:
android middle

Android code:

// @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
}

An improved version of the code can be found in the most examples:

    // @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
    }

improved android

Some differences are:
- the right side of the view doesn't move as how the iOS.

Here is the Android Camera axes:
axes

I do believe a traslation on Z axes doesn't fix it. Maybe needed a shrink too somehow.

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

Still not enough. To much is the shrink the left side.

z

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文