8

I'm trying to use Android's new CardView in a rotation animation. However, the when the CardView's rotationY property is set high enough, some really bad things happen on Lollipop devices. Here's some example code that is pretty easy to compile:

MainActivity.java:

public class MainActivity extends Activity {

    private CardView mTestView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTestView = (CardView) findViewById(R.id.test_view);

        mTestView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTestView.animate()
                        .rotationY(360)
                        .setDuration(3000);
            }
        });
    }
}

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

    <android.support.v7.widget.CardView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/test_view">
    </android.support.v7.widget.CardView>
</RelativeLayout>

After clicking on the view, you'll see a neat rotation animation complete with the Material Design shadows and everything. But once the card's rotation angle gets above approximately 60, it will either stop rendering, or render several frames without clearing the previous frame, or some mixture of the two. This continues until the card's angle is back below this threshold.

Now, this animation is set to take 3 seconds - which is ridiculous. At a more realistic animation speed (say, animation duration 300ms) this is still visible but really just looks like a temporary microstutter.

It seems like a possible bug in the framework - but it could also be that I need to call some additional method to allow the rotation to go off without a problem. Ideas?

Note: Setting the camera distance by calling View.setCameraDistance() doesn't solve the problem; in fact if you just compile the above code with an insanely high (~100,000) distance, the issue still happens, but with a higher angle threshold (somewhere around 80-85, if I had to guess.)

sigmabeta
  • 1,174
  • 1
  • 12
  • 28
  • Did you get this bug fixed? Suffering from the same bug currently. – jehna1 Mar 15 '16 at 15:22
  • I never tried the fix suggested below. It sounds correct, though. I can give it a shot in roughly 12 hours and let you know if it worked or not. – sigmabeta Mar 15 '16 at 17:06

1 Answers1

0

Here is the solution on following post.

Android View Disappearing When Go Outside Of Parent

Given a setting that not to clip child view on the ViewGroup the animation views are belong to.

android:clipChildren="false"
android:clipToPadding="false"
Shawn Lu
  • 141
  • 1
  • 9
  • I think the linked to solution is to a different problem than \@sigmabeta describes in this question. \@sigmabeta is attempting to rotate a view around the Y axis only, and it clips when one edge gets too near the viewer (in the Z plane). The referenced solution deals with 2d animation in the Y plane only. See http://stackoverflow.com/q/23682708/5025060 for coverage of Z plane clipping issues. – CODE-REaD Nov 10 '16 at 17:12