我正在使用此代码将视图从x位置移动到另一个x位置:
int xStart=100,xEnd=500;
ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(view, "translationX", xStart, xEnd);
objectAnimator.setDuration(duration);
objectAnimator.start();
但我需要移动和旋转。
如何一起旋转和移动视图?
有可能的 ?
您可以使用它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] 删除。
我来说两句