Android 動(dòng)畫(huà)之TranslateAnimation應(yīng)用詳解
AlphaAnimation 透明度動(dòng)畫(huà)效果
ScaleAnimation 縮放動(dòng)畫(huà)效果
TranslateAnimation 位移動(dòng)畫(huà)效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫(huà)效果
本節(jié)講解TranslateAnimation動(dòng)畫(huà),TranslateAnimation比較常用,比如QQ,網(wǎng)易新聞菜單條的動(dòng)畫(huà),就可以用TranslateAnimation實(shí)現(xiàn),
通過(guò)TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 來(lái)定義動(dòng)畫(huà)
參數(shù)說(shuō)明:
float fromXDelta 動(dòng)畫(huà)開(kāi)始的點(diǎn)離當(dāng)前View X坐標(biāo)上的差值
float toXDelta 動(dòng)畫(huà)結(jié)束的點(diǎn)離當(dāng)前View X坐標(biāo)上的差值
float fromYDelta 動(dòng)畫(huà)開(kāi)始的點(diǎn)離當(dāng)前View Y坐標(biāo)上的差值
float toYDelta 動(dòng)畫(huà)開(kāi)始的點(diǎn)離當(dāng)前View Y坐標(biāo)上的差值
常用方法:
animation.setDuration(long durationMillis);//設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間
animation.setRepeatCount(int i);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行
Xml屬性:
android:duration:運(yùn)行動(dòng)畫(huà)的時(shí)間
android:repeatCount:定義動(dòng)畫(huà)重復(fù)的時(shí)間
代碼:
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è)置位移動(dòng)畫(huà) 向右位移150 */
final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);
animation.setDuration(2000);//設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間
animation.setRepeatCount(2);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行
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();
}
});
}
}
效果:
相關(guān)文章
Kotlin淺析延遲初始化與密封類(lèi)的實(shí)現(xiàn)方法
Kotlin語(yǔ)言的許多特性,包括變量不可變,變量不可為空,等等。這些特性都是為了盡可能地保證程序安全而設(shè)計(jì)的,但是有些時(shí)候這些特性也會(huì)在編碼時(shí)給我們帶來(lái)不少的麻煩,下面我們來(lái)了解延遲初始化和密封類(lèi)的特點(diǎn)2022-08-08
Android Studio 全屏沉浸式透明狀態(tài)欄效果的實(shí)現(xiàn)
這篇文章主要介紹了Android Studio 全屏沉浸式透明狀態(tài)欄效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
monkeyrunner之安卓開(kāi)發(fā)環(huán)境搭建教程(1)
這篇文章主要介紹了monkeyrunner之安卓開(kāi)發(fā)環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
Android編程實(shí)現(xiàn)號(hào)碼歸屬地查詢(xún)的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)號(hào)碼歸屬地查詢(xún)的方法,涉及Android xml文件的發(fā)送及WebService的操作技巧,需要的朋友可以參考下2016-01-01
Android中常用的三個(gè)Dialog彈窗總結(jié)解析
自己雖然一直使用過(guò)dialog,但是一直都是復(fù)制、粘貼;不清楚dialog的具體用途,這次趁著有時(shí)間,總結(jié)一下具體用法,感興趣的朋友跟著小編來(lái)看看吧2021-10-10
Android編程實(shí)現(xiàn)自動(dòng)檢測(cè)版本及自動(dòng)升級(jí)的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)自動(dòng)檢測(cè)版本及自動(dòng)升級(jí)的方法,涉及Android版本檢測(cè),匹配,下載及自動(dòng)安裝等技巧,需要的朋友可以參考下2016-01-01
EditText限制輸入數(shù)字,精確到小數(shù)點(diǎn)后1位的設(shè)置方法
下面小編就為大家?guī)?lái)一篇EditText限制輸入數(shù)字,精確到小數(shù)點(diǎn)后1位的設(shè)置方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
Android 倒計(jì)時(shí)控件 CountDownView的實(shí)例代碼詳解
這篇文章主要介紹了Android 倒計(jì)時(shí)控件 CountDownView的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06
Android 驗(yàn)證碼功能實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 驗(yàn)證碼功能實(shí)現(xiàn)代碼的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08

