Android 動(dòng)畫(huà)之RotateAnimation應(yīng)用詳解
更新時(shí)間:2012年12月02日 16:29:21 作者:
本節(jié)講解旋轉(zhuǎn)動(dòng)畫(huà)效果RotateAnimation方法的應(yīng)用,有需要的朋友可以參考下
android中提供了4中動(dòng)畫(huà):
AlphaAnimation 透明度動(dòng)畫(huà)效果
ScaleAnimation 縮放動(dòng)畫(huà)效果
TranslateAnimation 位移動(dòng)畫(huà)效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫(huà)效果
本節(jié)講解RotateAnimation 動(dòng)畫(huà),
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說(shuō)明:
float fromDegrees:旋轉(zhuǎn)的開(kāi)始角度。
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)動(dòng)畫(huà) */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動(dòng)畫(huà)執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時(shí)間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開(kāi)始動(dòng)畫(huà) */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動(dòng)畫(huà) */
animation.cancel();
}
});
}
}
效果:
AlphaAnimation 透明度動(dòng)畫(huà)效果
ScaleAnimation 縮放動(dòng)畫(huà)效果
TranslateAnimation 位移動(dòng)畫(huà)效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫(huà)效果
本節(jié)講解RotateAnimation 動(dòng)畫(huà),
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說(shuō)明:
float fromDegrees:旋轉(zhuǎn)的開(kāi)始角度。
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)動(dòng)畫(huà) */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動(dòng)畫(huà)執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時(shí)間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開(kāi)始動(dòng)畫(huà) */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動(dòng)畫(huà) */
animation.cancel();
}
});
}
}
效果:
您可能感興趣的文章:
- Android Tween動(dòng)畫(huà)之RotateAnimation實(shí)現(xiàn)圖片不停旋轉(zhuǎn)效果實(shí)例介紹
- Android 動(dòng)畫(huà)之TranslateAnimation應(yīng)用詳解
- Android 動(dòng)畫(huà)之ScaleAnimation應(yīng)用詳解
- Android 動(dòng)畫(huà)之AlphaAnimation應(yīng)用詳解
- 三款A(yù)ndroid炫酷Loading動(dòng)畫(huà)組件推薦
- Android實(shí)現(xiàn)Activity界面切換添加動(dòng)畫(huà)特效的方法
- Android 使用XML做動(dòng)畫(huà)UI的深入解析
- Android啟動(dòng)畫(huà)面的實(shí)現(xiàn)方法
- Android 吸入動(dòng)畫(huà)效果實(shí)現(xiàn)分解
- Android動(dòng)畫(huà)之3D翻轉(zhuǎn)效果實(shí)現(xiàn)函數(shù)分析
- Android編程實(shí)現(xiàn)RotateAnimation設(shè)置中心點(diǎn)旋轉(zhuǎn)動(dòng)畫(huà)效果
相關(guān)文章
取消Android Studio項(xiàng)目與SVN關(guān)聯(lián)的方法
今天小編就為大家分享一篇關(guān)于取消Android Studio項(xiàng)目與SVN關(guān)聯(lián)的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
Android點(diǎn)擊事件之多點(diǎn)觸摸與手勢(shì)識(shí)別的實(shí)現(xiàn)
這篇文章主要介紹了Android點(diǎn)擊事件之多點(diǎn)觸摸與手勢(shì)識(shí)別的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
Android實(shí)現(xiàn)加載對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)加載對(duì)話框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01
詳解Flutter中StatefulBuilder組件的使用
StatefulBuilder小部件可以在這些區(qū)域的狀態(tài)發(fā)生變化時(shí)僅重建某些小區(qū)域而無(wú)需付出太多努力。本文將來(lái)詳細(xì)講講它的使用,需要的可以參考一下2022-05-05
Android編程實(shí)現(xiàn)檢測(cè)當(dāng)前電源狀態(tài)的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)檢測(cè)當(dāng)前電源狀態(tài)的方法,涉及Android針對(duì)當(dāng)前電源的電量、容量、伏數(shù)、溫度等的檢測(cè)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-11-11

