Card flip Animation not looking good on Android 7 Nougat

276 Views Asked by At

thank you for reading my question. The problem I have only occurs in android 7.0 (Nougat) and what it's happening is that the card (a fragment with Image views) when it rotates in the animation, it suddenly crops part of the image, Look:

Android 7 Nougat Screenshoot

Card in rotation

Android 4.4 Kitkat Screenshoot

Card in rotation

I'm using Animation (not objectAnimator yet), Here's my code:

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Angle around the y-axis of the rotation at the given time
    // calculated both in radians and degrees.
    final double radians = Math.PI * interpolatedTime;
    float degrees = (float) (180.0 * radians / Math.PI);

    Log.d(LOG_TAG," "+interpolatedTime);

    // Once we reach the midpoint in the animation, we need to hide the
    // source view and show the destination view. We also need to change
    // the angle by 180 degrees so that the destination does not come in
    // flipped around
    if (interpolatedTime >= 0.5f) {
        degrees -= 180.f;
        fromView.setVisibility(View.GONE);
        toView.setVisibility(View.VISIBLE);

    }

    if (forward)
        degrees = -degrees; //determines direction of rotation when flip begins


    //computing
    final Matrix matrix = t.getMatrix();
    camera.save();
    camera.translate(0, 0, Math.abs(degrees) * 3f);
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}

Thank you so much for sharing your ideas. :)

1

There are 1 best solutions below

2
barotia On

Read the https://developer.android.com/reference/android/view/View.html#setCameraDistance(float)

You have to set the camera distance. I know that this question is old, but I hope that will help somebody.