Android視頻教程AlphaAnimation詳解
0
常見的android視頻教程中經常會提到如下4種動畫效果:
1、AlphaAnimation 透明度動畫效果
2、ScaleAnimation 縮放動畫效果
3、TranslateAnimation 位移動畫效果
4、RotateAnimation 旋轉動畫效果
這4種效果是當今android開發的主流手段,一般大型的android開發項目中都會用到。對于android初學者來說,必須要牢牢掌握這4種效果。今天主要講解AlphaAnimation透明度動畫效果的實現方法。常用于窗口動畫效果、LOGO淡入淡出的實現。
android開發 AlphaAnimation代碼示例:
1、AlphaAnimation 透明度動畫效果
2、ScaleAnimation 縮放動畫效果
3、TranslateAnimation 位移動畫效果
4、RotateAnimation 旋轉動畫效果
這4種效果是當今android開發的主流手段,一般大型的android開發項目中都會用到。對于android初學者來說,必須要牢牢掌握這4種效果。今天主要講解AlphaAnimation透明度動畫效果的實現方法。常用于窗口動畫效果、LOGO淡入淡出的實現。
android開發 AlphaAnimation代碼示例:
-
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);
-
/** 設置透明度漸變動畫 */
-
final AlphaAnimation animation = new AlphaAnimation(1, 0);
-
animation.setDuration(2000);//設置動畫持續時間
-
/** 常用方法 */
-
//animation.setRepeatCount(int repeatCount);//設置重復次數
-
//animation.setFillAfter(boolean);//動畫執行完后是否停留在執行完的狀態
-
//animation.setStartOffset(long startOffset);//執行前的等待時間
-
start.setOnClickListener(new OnClickListener() {
-
public void onClick(View arg0) {
-
image.setAnimation(animation);
-
/** 開始動畫 */
-
animation.startNow();
-
}
-
});
-
cancel.setOnClickListener(new OnClickListener() {
-
public void onClick(View v) {
-
/** 結束動畫 */
-
animation.cancel();
-
}
-
});
-
}
- }