Android - Flip Animation doesn't flip smoothly

I want my image to be rotated horizontally 4 times and at the same time to reduce it.

I have the following code for flipping:

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

And for scaling, I have the following code in 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> 

However, when I run my application on an emulator in eclipse, the inverted image shows an uncomfortable effect. As you can see from the images, sometimes when turning one vertical side is longer than the other, making the effect of stretching, which I do not want. Anyone help eliminate this effect?

enter image description hereenter image description hereenter image description here

+5
source share
1 answer

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

Sets the distance along the Z axis (orthogonal to the X / Y plane for which views are drawn) from the camera to this view. Camera distance affects 3D transformations, such as rotation around X and Y. If the rotationX or rotY properties are changed and this view is large (more than half the screen size), it is recommended that you always use a camera distance that is greater than height (rotation of the X axis) or width (rotation of the Y axis) of this species.

The distance from the camera to the viewing plane can affect the perspective distortion of the view when it rotates around x or the y axis. For example, a large distance will lead to a wide viewing angle, and there will not be much distortion of the perspective view when it rotates. Over a short distance, there may be much greater perspective distortion during rotation, and can also lead to some artifact drawing if the rotated view is partially beyond (therefore, it is recommended to use a distance not less than the size of the view if the view should be rotated.)

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

 view.setCameraDistance(10 * view.getWidth()); 
+5
source

Source: https://habr.com/ru/post/980305/


All Articles