2014-04-04 61 views
1

我正在用android xml動畫掙扎。我想圍繞其中心點逆時針旋轉圖像。Android動畫在中心點周圍旋轉圖像

這裏是我的動畫XML:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="true" > 

<rotate 
    android:duration="1000" 
    android:repeatCount="infinite" 
    android:repeatMode="restart" 
    android:fromDegrees="360" 
    android:toDegrees="0" 
    android:pivotX="0.5" 
    android:pivotY="0.5"   
    android:interpolator="@android:anim/linear_interpolator"   
    /> 

沒有這個當前動畫繞點x = 0的圖像; y = 0。

+1

你必須設置pivotX和pivotY到「50%」 – Mahfa

+0

Yuu是驚人的。我嘗試了各種數字。我從來沒有想過要嘗試% – Zapnologica

+0

歡迎您 – Mahfa

回答

3

回答代表@Mahfa

必須設置pivotX和pivotY爲 「50%」

ŧ他的重要部分是百分比。

0

我認爲你需要使用一個Matrix對象。我做了同樣的前一段時間,我記得我有比你同樣的問題:

Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); 
Canvas canvas = new Canvas(targetBitmap); 
Matrix matrix = new Matrix(); 
matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); 
canvas.drawBitmap(source, matrix, new Paint()); 

編輯:使用此功能具有定時處理

public Bitmap rotateImage(int angle, Bitmap bitmapSrc) { 
Matrix matrix = new Matrix(); 
matrix.postRotate(angle); 
return Bitmap.createBitmap(bitmapSrc, 0, 0, 
     bitmapSrc.getWidth(), bitmapSrc.getHeight(), matrix, true); 

}

+0

我希望在xml文件中做到這一點?因爲我在整個應用程序中使用這個動畫。 – Zapnologica