Android中如何限制旋转投影?RotationY视图变形问题求助
Hey there! I totally get your frustration—when using RotationY() on a view, that default perspective projection turns your nice rectangle into a skewed parallelogram, and you just want a clean rotation without any shape distortion. Let’s fix this right away.
The Root Cause
The default camera distance for views is pretty small, so when you rotate around the Y-axis, the perspective effect (near side appearing larger, far side smaller) is super noticeable, making your view look like a parallelogram. To avoid this, we just need to crank up the camera distance to minimize that perspective distortion.
Step-by-Step Solution
Set a Large Camera Distance First
Before starting your animation, set a sufficiently large camera distance on your view. We use the screen density to make this value consistent across different devices:float scale = getResources().getDisplayMetrics().density; myview.setCameraDistance(10000 * scale); // Adjust the number if needed—bigger = less perspectiveRun Your Existing Animation
Now when you execute your rotation animation, the view will rotate cleanly around the Y-axis without changing its projected shape:myview.Animate() .RotationY(rotationangle) .X(xposition) .SetDuration(mduration) .WithLayer() .SetInterpolator(interpolate) .Start();
Alternative: Use ObjectAnimator
If you prefer using ObjectAnimator instead of the view animator, the same logic applies—just set the camera distance first, then run the animator:
float scale = getResources().getDisplayMetrics().density; myview.setCameraDistance(10000 * scale); ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(myview, "rotationY", 0f, rotationangle); rotationAnim.setDuration(mduration); rotationAnim.setInterpolator(interpolate); rotationAnim.start();
Why This Works
By increasing the camera distance, we’re making the "virtual camera" that renders the view much farther away. This reduces the perspective distortion to the point where it’s invisible to the human eye, so your view stays a crisp rectangle while rotating around the Y-axis.
内容的提问来源于stack exchange,提问作者Hemalatha M.R.

