2017-08-02 19 views
0

如何使用Java中的float值將RotateAnimation()格式的XML轉換爲?

<rotate 
    android:duration="5000" 
    android:fromDegrees="270" 
    android:pivotX="50%" 
    android:pivotY="100%" 
    android:repeatCount="0" 
    android:startOffset="0" 
    android:toDegrees="360" /> 

欲動態傳遞度,因此在想RotateAnimation的()。但無法按照RotateAnimation構造函數的要求將所有參數轉換爲浮動。

+0

有啥說法是,你不能轉換? – pskink

+0

我想通過toDegrees參數作爲動態值。 – Neha

+0

所以使用帶'toDegrees'參數的RotateAnimation'構造函數 – pskink

回答

0

像這樣在您的常規ImageView上使用旋轉動畫。

Matrix matrix = new Matrix(); 
imageView.setScaleType(ImageView.ScaleType.MATRIX); //required 
matrix.postRotate((float) angle, pivotX, pivotY); 
imageView.setImageMatrix(matrix); 
+0

Mahesh,我想動態旋轉圖像。我不想要XML。 – Neha

+0

@Neha看到我編輯的答案 –

+0

謝謝,但我解決了它的其他方式。 – Neha

0

這是爲我工作:

int i=seekbar.getProgress(); 
i=i-90; 
float **newFloat** = (float) i; 
rotation= new RotateAnimation(-90f,**newFloat**,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1.0f); 

rotation.setDuration(5000); 
rotation.setFillAfter(true); 
two.startAnimation(rotation); //two is an imageview 
相關問題