簡體   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