gpt4 book ai didi

Android - 翻转动画翻转不流畅

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:17 26 4
gpt4 key购买 nike

我想让我的图片水平翻转4次,同时缩小。

我有以下翻转代码:

ObjectAnimator flipAnimation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 1440f);
flipAnimation.setDuration(4000);
flipAnimation.start();

我在 scale_down.xml 中有以下代码用于缩小:

<scale
android:duration="4000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.1"
android:toYScale="0.1" >
</scale>

但是,当我在 eclipse 的模拟器上运行我的应用程序时,翻转图像显示出一种尴尬的效果。从图片中可以看出,有时在翻转时,垂直的一侧比另一侧长,产生拉伸(stretch)效果,这不是我想要的。有什么有助于消除这种影响的吗?

enter image description here enter image description here enter image description here

最佳答案

这种效果称为透视变形。这正是setCameraDistance()用于:

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. 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.

The distance of the camera from the view plane can have an affect on the perspective distortion of the view when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

您可能想要修改该值,具体取决于 View 的尺寸和您想要实现的视觉效果。我得到了一个很好的结果:

view.setCameraDistance(10 * view.getWidth());

关于Android - 翻转动画翻转不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24592731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com