2012-03-13 96 views
0

這是我在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" /> 

我想使動畫像這樣: enter image description here 綠線應轉動,旋轉點應該是在屏幕的中央。我怎樣才能做到這一點 ?

+0

目前還不清楚你目前的症狀是什麼,但它可能與此有關的問題:http://code.google.com/p/android/issues/detail?id=22969 – CommonsWare 2012-03-13 13:34:20

+2

@Lukap不應該將「android:pivotX」和「android:pivotY」都設置爲「50%」 – Selvin 2012-03-13 13:53:39

回答

-2

使用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);