xml中的旋转动画不会在中间旋转
问题描述:
这是我在xml中的动画,我尝试过使用android:pivotX =“50%”,但仍然没有得到我想要的。旋转的角度是错误的。我希望绿线围绕屏幕中间旋转。xml中的旋转动画不会在中间旋转
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator"
android:toDegrees="360" android:pivotX="0%" android:pivotY="0%"
android:repeatCount="5"
android:duration="5000" android:startOffset="0" />
我想使动画像这样: 绿线应转动,旋转点应该是在屏幕的中央。我怎样才能做到这一点 ?
答
使用RotateAnimation,将透视点设置为图像的中心。
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.splash);
splash.startAnimation(anim);
// Later.. stop the animation
splash.setAnimation(null);
目前还不清楚你目前的症状是什么,但它可能与此有关的问题:http://code.google.com/p/android/issues/detail?id=22969 – CommonsWare 2012-03-13 13:34:20
@Lukap不应该将“android:pivotX”和“android:pivotY”都设置为“50%” – Selvin 2012-03-13 13:53:39