4

I'm attempting to put together a slick animation in which a view that takes up most of the screen space rotates to reveal another view on the rear side:

rotatingView.animate().rotationY(90)
            .setDuration(250)
            .setInterpolator(new AccelerateInterpolator())
            .withEndAction( /* Runnable that sets up the rear side of the view,
                               then rotates Y another 90 degrees */);

Problem is, about 80% of the way through this animation, the view disappears. The view doesn't reappear until about 20% of the way into the second half. Put another way, it disappears at 11 o'clock and reappears at 1 o'clock. Why is this?

sigmabeta
  • 1,174
  • 1
  • 12
  • 28
  • I'm having this same problem, and I am setting it up with XML. It only occurs (so far as I've seen) on 4.4, though I haven't been able to test on anything between 4.1.2 and there. It also doesn't occur when it is rotationX. – Joey Harwood Mar 23 '15 at 14:44
  • That's an interesting data point. That makes it sound like it is a framework bug. – sigmabeta Mar 23 '15 at 14:49
  • 1
    Yeah, I've been doing some research, in the version notes it mentions a new Framework for UI transitions for 4.4. I've noticed that in my 4.1.2 transitions, the top and bottom of the fragment stays glued to the top and bottom of the screen, whereas in the 4.4 rotation allows the rotation to have perspective, sinking into the screen or expanding up out of the screen depending on the side. I'm assuming since it's near the point where the expansion of rising side would start to approach infinite that they simply cut off the animation. I think it's more of a lazy solution that a bug unfortunately – Joey Harwood Mar 23 '15 at 15:41
  • So, it actually turns out I asked another question that is similar to this one (but focuses on a 5.x specific consequence) a month or two ago. Try using setCameraDistance on your view and see if it helps. http://stackoverflow.com/questions/28228659/cardview-displays-artifacts-when-rotationy-60 – sigmabeta Mar 23 '15 at 15:46
  • I'm actually looking at combining a fade animation with the rotate animation so that the disappearing ends up looking natural. The set camera distance is an interesting solution, but I'm nervous of other side effects it could have elsewhere. Thanks for sharing your experience though, and good luck! – Joey Harwood Mar 23 '15 at 15:52
  • @sigmabeta, interesting pointer to `setCameraDistance`. The [doc](https://developer.android.com/reference/android/view/View.html#setCameraDistance(float)) says, *If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.* – CODE-REaD Nov 05 '16 at 16:00

1 Answers1

0

I finally stumbled on the answer to this type of problem. UsesetCameraDistance(), but note that:

The distance is expressed in "depth pixels." The default distance depends on the screen density. For instance, on a medium density display, the default distance is 1280. On a high density display, the default distance is 1920.

So, to "raise" the camera to the point where the near edge of a view doesn't clip it, set the distance to several times the "default" distance. In my case with several tablet screens, a value of 4000f was needed. See the link for more onsetCameraDistance()parameter calculation.

You may want to combinesetCameraDistance()with clipToPadding="false" and clipChildren="false" in your XML file; these control masking of one view by another.

Also, I suspect YMMV across different Android releases and vendors.

CODE-REaD
  • 2,819
  • 3
  • 33
  • 60