Android 動畫之ScaleAnimation應(yīng)用詳解
更新時間:2012年12月02日 16:24:51 作者:
本節(jié)講解ScaleAnimation 動畫在應(yīng)用中的實現(xiàn),有需要的朋友可以參考下
android中提供了4中動畫:
AlphaAnimation 透明度動畫效果
ScaleAnimation 縮放動畫效果
TranslateAnimation 位移動畫效果
RotateAnimation 旋轉(zhuǎn)動畫效果
本節(jié)講解ScaleAnimation 動畫,
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
float fromX 動畫起始時 X坐標(biāo)上的伸縮尺寸
float toX 動畫結(jié)束時 X坐標(biāo)上的伸縮尺寸
float fromY 動畫起始時Y坐標(biāo)上的伸縮尺寸
float toY 動畫結(jié)束時Y坐標(biāo)上的伸縮尺寸
int pivotXType 動畫在X軸相對于物件位置類型
float pivotXValue 動畫相對于物件的X坐標(biāo)的開始位置
int pivotYType 動畫在Y軸相對于物件位置類型
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è)置縮放動畫 */
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è)置動畫持續(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é)講解ScaleAnimation 動畫,
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數(shù)說明:
復(fù)制代碼 代碼如下:
float fromX 動畫起始時 X坐標(biāo)上的伸縮尺寸
float toX 動畫結(jié)束時 X坐標(biāo)上的伸縮尺寸
float fromY 動畫起始時Y坐標(biāo)上的伸縮尺寸
float toY 動畫結(jié)束時Y坐標(biāo)上的伸縮尺寸
int pivotXType 動畫在X軸相對于物件位置類型
float pivotXValue 動畫相對于物件的X坐標(biāo)的開始位置
int pivotYType 動畫在Y軸相對于物件位置類型
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è)置縮放動畫 */
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è)置動畫持續(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();
}
});
}
}
效果:

相關(guān)文章
Android向node.js編寫的服務(wù)器發(fā)送數(shù)據(jù)并接收請求
這篇文章主要為大家詳細(xì)介紹了Android向node.js編寫的服務(wù)器發(fā)送數(shù)據(jù),并接收請求,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法
這篇文章主要介紹了詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12Android中Bitmap、File與Uri之間的簡單記錄
這篇文章主要給大家介紹了關(guān)于Android中Bitmap、File與Uri之間的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02Android中關(guān)于Binder常見面試問題小結(jié)
這篇文章主要介紹了Android中關(guān)于Binder幾個面試問題,binder是一種進(jìn)程間通訊的機(jī)制,進(jìn)程間通訊需要了解用戶空間和內(nèi)核空間,本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06