在android中移动和旋转视图

测试栈

我正在使用此代码将视图从x位置移动到另一个x位置:

int xStart=100,xEnd=500;
ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(view, "translationX", xStart, xEnd);
objectAnimator.setDuration(duration);
objectAnimator.start();

但我需要移动和旋转。

如何一起旋转和移动视图?

有可能的 ?

布莱恩·赫伯斯特(Bryan Herbst)

您可以使用它ObjectAnimator来为View的任何属性设置动画,基本上可以使用set___()get___()方法为任何属性设置动画

对于旋转,你可以用"rotation""rotationX""rotationY"为适当。

听起来您的翻译工作正常,所以我不确定您在“移动”视图时还需要什么。

要一起播放多个动画,可以使用AnimatorSet要同时移动和旋转,可以执行以下操作:

AnimatorSet animations = new AnimatorSet();
ObjectAnimator translationAnim= ObjectAnimator.ofFloat(view, "translationX", 100, 500);
ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(view, "rotation", 0, 90);
animations.play(rotationAnim).with(translationAnim);
animations.start();

有关更多信息,请参见属性动画文档

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章