从视图中心旋转动画不起作用

Arm*_*adi 2 android pivot center rotateanimation

我想为我的视图制作一个旋转动画但是在两边(java和xml)我无法找到任何方法从它的中心旋转视图

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="180" />
Run Code Online (Sandbox Code Playgroud)

还有这个:

RotateAnimation animation = new RotateAnimation(0,180,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);
Run Code Online (Sandbox Code Playgroud)

它们都从角落旋转视图

请帮我

小智 8

看起来你尝试旋转所有布局,而不是视图.你需要的.工作代码

View view = findViewById( R.id.image );
aRotate = new RotateAnimation(fStartAngle, fEndAngle,
          Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

aRotate.setStartOffset(0);
aRotate.setDuration(2000);
aRotate.setFillAfter(true);
aRotate.setInterpolator(context, android.R.anim.decelerate_interpolator);

view.startAnimation(aRotate);
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!我在使用 `view.setAnimation` 而不是 `view.startAnimation` 时遇到了问题。 (2认同)