Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 533
Shreyash Mahajan Avatar asked Dec 14 '11 05:12

Shreyash Mahajan


People also ask

How do you flip the screen on Android?

You can flip a layout by setting the View property scaleX to -1. So View#setScaleX(1f) is normal, and View#setScaleX(-1f) is flipped (visually). To do it pre-Honeycomb, you can use scale properties in the general Animation library.

What is Crossfade in Android?

Crossfade animations (also know as dissolve) gradually fade out one UI component while simultaneously fading in another. This animation is useful for situations where you want to switch content or views in your app. Crossfades are very subtle and short but offer a fluid transition from one screen to the next.

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

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

like image 135
matheszabi Avatar answered Oct 08 '22 00:10

matheszabi