Android 動畫之RotateAnimation應(yīng)用詳解
更新時間:2012年12月02日 16:29:21 作者:
本節(jié)講解旋轉(zhuǎn)動畫效果RotateAnimation方法的應(yīng)用,有需要的朋友可以參考下
android中提供了4中動畫:
AlphaAnimation 透明度動畫效果
ScaleAnimation 縮放動畫效果
TranslateAnimation 位移動畫效果
RotateAnimation 旋轉(zhuǎn)動畫效果
本節(jié)講解RotateAnimation 動畫,
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
float fromDegrees:旋轉(zhuǎn)的開始角度。
float toDegrees:旋轉(zhuǎn)的結(jié)束角度。
int pivotXType:X軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐標(biāo)的伸縮值。
int pivotYType:Y軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐標(biāo)的伸縮值。
代碼:
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);
/** 設(shè)置旋轉(zhuǎn)動畫 */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//設(shè)置動畫持續(xù)時間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動畫執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動畫 */
animation.cancel();
}
});
}
}
效果:
AlphaAnimation 透明度動畫效果
ScaleAnimation 縮放動畫效果
TranslateAnimation 位移動畫效果
RotateAnimation 旋轉(zhuǎn)動畫效果
本節(jié)講解RotateAnimation 動畫,
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
float fromDegrees:旋轉(zhuǎn)的開始角度。
float toDegrees:旋轉(zhuǎn)的結(jié)束角度。
int pivotXType:X軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐標(biāo)的伸縮值。
int pivotYType:Y軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐標(biāo)的伸縮值。
代碼:
復(fù)制代碼 代碼如下:
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);
/** 設(shè)置旋轉(zhuǎn)動畫 */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//設(shè)置動畫持續(xù)時間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動畫執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動畫 */
animation.cancel();
}
});
}
}
效果:

您可能感興趣的文章:
- Android Tween動畫之RotateAnimation實現(xiàn)圖片不停旋轉(zhuǎn)效果實例介紹
- Android 動畫之TranslateAnimation應(yīng)用詳解
- Android 動畫之ScaleAnimation應(yīng)用詳解
- Android 動畫之AlphaAnimation應(yīng)用詳解
- 三款A(yù)ndroid炫酷Loading動畫組件推薦
- Android實現(xiàn)Activity界面切換添加動畫特效的方法
- Android 使用XML做動畫UI的深入解析
- Android啟動畫面的實現(xiàn)方法
- Android 吸入動畫效果實現(xiàn)分解
- Android動畫之3D翻轉(zhuǎn)效果實現(xiàn)函數(shù)分析
- Android編程實現(xiàn)RotateAnimation設(shè)置中心點旋轉(zhuǎn)動畫效果
相關(guān)文章
Android RecyclerView實現(xiàn)水平、垂直方向分割線
這篇文章主要為大家詳細介紹了Android RecyclerView實現(xiàn)水平、垂直方向分割線,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07使用Broadcast實現(xiàn)Android組件間的通信
這篇文章主要為大家詳細介紹了使用Broadcast實現(xiàn)Android組件間的通信,感興趣的小伙伴們可以參考一下2016-06-06Android開發(fā)實現(xiàn)帶有反彈效果仿IOS反彈scrollview教程詳解
本文給大家分享android開發(fā)實現(xiàn)帶有反彈效果,模仿ios反彈scrollview詳細教程,本文介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起看看吧2016-09-09Android實現(xiàn)手勢滑動多點觸摸放大縮小圖片效果
這篇文章主要介紹了Android實現(xiàn)手勢滑動多點觸摸放大縮小圖片效果的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-02-02Flutter List數(shù)組避免插入重復(fù)數(shù)據(jù)的實現(xiàn)
這篇文章主要介紹了Flutter List數(shù)組避免插入重復(fù)數(shù)據(jù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Android開發(fā)手冊TextView屬性實現(xiàn)效果盤點
這篇文章主要為大家介紹了Android開發(fā)手冊TextView屬性實現(xiàn)的效果盤點及使用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06