简体   繁体   中英

Android elevated view animation not smooth

I want to rotate a simple imageview which has an elevation of 5dp.

  animRotate=ObjectAnimator.ofFloat(imgProgress, "rotationY", 0, 360); animRotate.setDuration(ANIM_DURATION); animRotate.setRepeatCount(5); animRotate.start(); 

The animation for the above code is smooth if the android:elevation value for the ImageView is not set in the layout file. But when i set the elevation, the animation becomes jerky.

Can someone please suggest a fix?

Maybe the reason is that you create and run animatuion at once. As docs say, it is better first to init your animation

//OnCreate
animRotate=ObjectAnimator.ofFloat(imgProgress, "rotationY", 0, 360);
animRotate.setDuration(ANIM_DURATION);
animRotate.setRepeatCount(5);

And then when it is time for animation to be fired run it

animRotate.start();

Also, consider reading about what PivotX and PivotY are, it may be useful.

Also, using default interpolator will give strange result for rotating 5 times - i think using simple linear interpolator is much better choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM