日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 动画AlphaAnimation类方法

發(fā)布時間:2024/4/15 Android 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 动画AlphaAnimation类方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

當我們打開應用時,出現(xiàn)在我們眼前的是一張漸變圖片。此圖可以是應用歡迎圖片,也可以廣告海報(服務可以推送廣告),就是用到了動畫AlphaAnimation完成的。


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);//設置動畫持續(xù)時間?
/** 常用方法 */?
//animation.setRepeatCount(int repeatCount);//設置重復次數(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) {?
/** 結束動畫 */?
animation.cancel();?
}?
});?
}?


一、所使用的技術:AlphaAnimation動畫

1。官方描述:
An animation that controls the alpha level of an object. Useful for fading things in and out. This animation ends up changing the alpha property of a Transformation
即:控制對象alpha水平的動畫。這個動畫可以通過改變alpha屬性,達到漸進漸出的效果。

2。構造方法:AlphaAnimation(float fromAlpha, float toAlpha)
官方解釋:Constructor to use when building an AlphaAnimation from code
即:使用代碼實現(xiàn)漸變動畫
如:AlphaAnimation(0.01f, 1.0f); 從0.01f到1.0f漸變。學過flash的,應該對alpha值很了解,0.0是完全透明,1.0完全不透明。

二、動畫的實現(xiàn)
1。實例化對象
AlphaAnimation anim = new AlphaAnimation(0.01f, 1.0f);
2。設置動畫持續(xù)時長(兩秒)
anim.setDuration(2000);
3。添加事件監(jiān)聽
anim.setAnimationListener(new Animation.AnimationListener() {
?? ??? ??? ?
?? ?@Override
?? ?public void onAnimationStart(Animation animation) {?? ?
?? ?}
?? ??? ??? ?
?? ?@Override
?? ?public void onAnimationRepeat(Animation animation) {?? ?
?? ?}
?? ??? ??? ?
?? ?@Override
?? ?public void onAnimationEnd(Animation animation) {
?? ??? ?//漸變動畫結束后,執(zhí)行此方法,跳轉到主界面?? ?
?? ?}
});

4。為控件綁定動畫效果
imageView.setAnimation(anim);

5。開始動畫

anim.start();


看到上面兩個地方開始動畫的方法不一樣,現(xiàn)在好像android里面已經(jīng)有一個新的方法

?public void startAnimation(Animation animation) {
? ? ? ? animation.setStartTime(Animation.START_ON_FIRST_FRAME);
? ? ? ? setAnimation(animation);
? ? ? ? invalidateParentCaches();
? ? ? ? invalidate(true);
? ? }


有點亂。

轉自:http://www.apkbus.com/blog-134260-54359.html

總結

以上是生活随笔為你收集整理的Android 动画AlphaAnimation类方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。