Android的 - 翻转动画不能翻转顺利顺利、动画、Android

2023-09-05 07:55:24 作者:煽情。

我想让我的图像水平翻转4次,并在同一时间缩放下来。

I want to make my image to flip horizontally for 4 times, and at the same time scaling it down.

我有以下的$ C $下翻转:

I have the following code for flipping:

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

和我有以下的code在scale_down.xml用于缩小:

And I have the following code in scale_down.xml for scaling down:

<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中运行我的应用程序,翻转图像显示了一个尴尬的效果。正如你可以从图片看,有时同时翻转,一个垂直侧边大于另一侧,使得拉伸效果,这不是我想要的。任何有助于消除这种效果?

However, when I run my app on emulator in eclipse, the flipping image shows an awkward effect. As you can see from the images, sometimes while flipping, one vertical side is longer than the other side, making a stretching effect, which is not what I want. Any helps to eliminate that effect?

推荐答案

这效应被称为透视失真。而这正是 setCameraDistance( ) 是:

That effect is called perspective distortion. And this is exactly what setCameraDistance() is for:

设定沿Z轴的距离(正交上于X / Y平面   哪些视图从相机到这种观点出)。相机的   距离会影响3D变换,对周围的实例的旋转   X和Y轴。如果还是的rotationX rotationY属性进行改变和   这种观点是大的(在屏幕的一半以上的大小),它是   建议始终使用照相机距离,该距离是大于   这一观点的高度(X轴旋转​​)或宽度(Y轴旋转)。

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.

这视图平面相机的距离可以具有影响上   视图当它绕x旋转的透视失真   或y轴。例如,一个大的距离将导致较大的   视角,并且也不会有多大透视失真   视图,因为它旋转。很短的距离可能会导致更多   透视失真在旋转时,也可能会导致一些   绘制文物如果旋转视图结束部分后面的   相机(这就是为什么建议是使用的距离至少   至于视图的大小,如果视图是要被旋转。)

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.)

您可能要摆弄的价值,取决于视图和您想要达到的视觉效果的尺寸。我得到了良好的效果:

You may want to fiddle with the value, depending on the dimensions of the view and the visual effect you want to achieve. I got a good result with:

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