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

前端 未结 4 658
孤街浪徒
孤街浪徒 2021-01-31 22:29

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

4条回答
  •  不知归路
    2021-01-31 23:18

    At iOS portrait:

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

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

    Here is the Android Camera 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.

提交回复
热议问题