Android 動(dòng)畫之ScaleAnimation應(yīng)用詳解
更新時(shí)間:2012年12月02日 16:24:51 作者:
本節(jié)講解ScaleAnimation 動(dòng)畫在應(yīng)用中的實(shí)現(xiàn),有需要的朋友可以參考下
android中提供了4中動(dòng)畫:
AlphaAnimation 透明度動(dòng)畫效果
ScaleAnimation 縮放動(dòng)畫效果
TranslateAnimation 位移動(dòng)畫效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫效果
本節(jié)講解ScaleAnimation 動(dòng)畫,
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
float fromX 動(dòng)畫起始時(shí) X坐標(biāo)上的伸縮尺寸
float toX 動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的伸縮尺寸
float fromY 動(dòng)畫起始時(shí)Y坐標(biāo)上的伸縮尺寸
float toY 動(dòng)畫結(jié)束時(shí)Y坐標(biāo)上的伸縮尺寸
int pivotXType 動(dòng)畫在X軸相對(duì)于物件位置類型
float pivotXValue 動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置
int pivotYType 動(dòng)畫在Y軸相對(duì)于物件位置類型
float pivotYValue 動(dòng)畫相對(duì)于物件的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è)置縮放動(dòng)畫 */
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);//設(shè)置動(dòng)畫持續(xù)時(shí)間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動(dòng)畫執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時(shí)間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動(dòng)畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動(dòng)畫 */
animation.cancel();
}
});
}
}
效果:
AlphaAnimation 透明度動(dòng)畫效果
ScaleAnimation 縮放動(dòng)畫效果
TranslateAnimation 位移動(dòng)畫效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫效果
本節(jié)講解ScaleAnimation 動(dòng)畫,
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
復(fù)制代碼 代碼如下:
float fromX 動(dòng)畫起始時(shí) X坐標(biāo)上的伸縮尺寸
float toX 動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的伸縮尺寸
float fromY 動(dòng)畫起始時(shí)Y坐標(biāo)上的伸縮尺寸
float toY 動(dòng)畫結(jié)束時(shí)Y坐標(biāo)上的伸縮尺寸
int pivotXType 動(dòng)畫在X軸相對(duì)于物件位置類型
float pivotXValue 動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置
int pivotYType 動(dòng)畫在Y軸相對(duì)于物件位置類型
float pivotYValue 動(dòng)畫相對(duì)于物件的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è)置縮放動(dòng)畫 */
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);//設(shè)置動(dòng)畫持續(xù)時(shí)間
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//設(shè)置重復(fù)次數(shù)
//animation.setFillAfter(boolean);//動(dòng)畫執(zhí)行完后是否停留在執(zhí)行完的狀態(tài)
//animation.setStartOffset(long startOffset);//執(zhí)行前的等待時(shí)間
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動(dòng)畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動(dòng)畫 */
animation.cancel();
}
});
}
}
效果:
相關(guān)文章
Android 模仿iPhone列表數(shù)據(jù)View刷新動(dòng)畫詳解
本文主要介紹Android 模仿iPhone列表數(shù)據(jù)view 刷新動(dòng)畫的資料,這里整理詳細(xì)的資料,并附示例代碼及實(shí)現(xiàn)效果圖,有興趣的小伙伴可以參考下2016-09-09
Flutter使用AnimatedOpacity實(shí)現(xiàn)圖片漸現(xiàn)動(dòng)畫
其實(shí)在Flutter中提供了一些封裝好的動(dòng)畫組件,以便我們快速應(yīng)用。本文將利用其中的AnimatedOpacity組件實(shí)現(xiàn)圖片漸現(xiàn)動(dòng)畫效果,需要的可以參考一下2022-03-03
Android性能優(yōu)化之JVMTI與內(nèi)存分配
這篇文章主要為大家介紹了Android性能優(yōu)化之JVMTI與內(nèi)存分配,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
使用Android studio3.6的java api方式調(diào)用opencv
這篇文章主要介紹了Android studio3.6的java api方式調(diào)用opencv的代碼詳解,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android開發(fā)ImageView圖片無法顯示解決過程
在Android中ImageView無法顯示加載的本地SDCard圖片:過程為先調(diào)用本地照相機(jī)程序攝像,然后將拍攝的圖片加載在ImageView中顯示,具體解決方法如下,感興趣的朋友可以參考下哈2013-06-06
Android 使用Vitamio打造自己的萬能播放器(9)—— 在線播放 (在線電視)
本文主要介紹Android 使用Vitamio開發(fā)播放器,實(shí)現(xiàn)在線電視播放,這里提供效果圖和實(shí)例代碼以便大家參考,2016-07-07
淺談Android Studio導(dǎo)出javadoc文檔操作及問題的解決
這篇文章主要介紹了淺談Android Studio導(dǎo)出javadoc文檔操作及問題的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android Studio debug.keystore位置介紹
這篇文章主要介紹了Android Studio debug.keystore位置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03

