標籤:
近期要寫的一個介面中包含一個旋轉的動畫。 所以就去網上找了下資料,
原文出處:http://www.jb51.net/article/32341.htm
本節講解RotateAnimation 動畫, RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 參數說明:
float fromDegrees:旋轉的開始角度。 float toDegrees:旋轉的結束角度。 int pivotXType:X軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。 float pivotXValue:X座標的伸縮值。 int pivotYType:Y軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。 float pivotYValue:Y座標的伸縮值。 代碼:
複製代碼 代碼如下:public class MainActivity extends Activity { ImageView image; Button start; Button cancel; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.main_img); start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel); /** 設定旋轉動畫 */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//設定動畫期間 /** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設定重複次數
//animation.setFillAfter(boolean);//動畫執行完後是否停留在執行完的狀態
//animation.setStartOffset(long startOffset);//執行前的等待時間
start.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { image.setAnimation(animation); /** 開始動畫 */
animation.startNow(); } }); cancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { /** 結束動畫 */
animation.cancel(); } }); } }
效果:
Android 動畫之RotateAnimation應用詳解