视图在RotationY动画快要结束时消失 [英] View disappears near end of RotationY animation
问题描述
我正在尝试制作一个光滑的动画,其中占据屏幕大部分空间的视图旋转以显示背面的另一个视图:
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 */);
问题在于,在此动画中,大约80%的视图消失了.直到下半年的大约20%时,该视图才重新出现.换句话说,它在11点消失,并在1点重新出现.为什么会这样?
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?
推荐答案
我终于偶然发现了此类问题的答案.使用setCameraDistance()
,但请注意:
I finally stumbled on the answer to this type of problem. UsesetCameraDistance()
, but note that:
距离以深度像素"表示.默认距离取决于屏幕密度.例如,在中等密度显示器上,默认距离是1280.在高密度显示器上,默认距离是1920.
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.
因此,要将摄像机提升"到视图的近边缘不会对其进行裁剪的点,请将距离设置为默认"距离的几倍.以我的几个平板电脑屏幕为例,需要4000f的值.有关setCameraDistance()
的更多信息,请参见链接.参数计算.
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.
您可能希望将XML文件中的setCameraDistance()
与clipToPadding="false"
和clipChildren="false"
组合在一起;这些控制一个视图对另一个视图的遮罩.
You may want to combinesetCameraDistance()
with clipToPadding="false"
and clipChildren="false"
in your XML file; these control masking of one view by another.
此外,我怀疑YMMV跨不同的Android版本和供应商.
Also, I suspect YMMV across different Android releases and vendors.
这篇关于视图在RotationY动画快要结束时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!