android中提供了3中動(dòng)畫(huà):
ScaleAnimation 縮放動(dòng)畫(huà)效果
TranslateAnimation 位移動(dòng)畫(huà)效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫(huà)效果
本節(jié)講解AlphaAnimation 動(dòng)畫(huà),窗口的動(dòng)畫(huà)效果,淡入淡出什么的,有些游戲的歡迎動(dòng)畫(huà),logo的淡入淡出效果就使用AlphaAnimation。
直接看代碼:
復(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)畫(huà) */
final AlphaAnimation animation = new AlphaAnimation(1, 0);
animation.setDuration(2000);//設(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();
}
});
}
}<SPAN style="COLOR: #333333; FONT-FAMILY: Microsoft YaHei"><SPAN style="FONT-SIZE: 14px; LINE-HEIGHT: 26px">
</SPAN></SPAN>
效果: