Android-Animations的使用大全之二:Frame Animation和其他
Android-Animations的使用大全之一:Tweened Animations詳解
?
5 Frame-By-Frame Animations的使用方
1 在res/drawable中創(chuàng)建一個(gè)xml文件,定義Animation的動畫播放序列 anim_nv.xml
?
Xml代碼??2 為ImageView設(shè)置背景資源
?
Java代碼??3 通過ImageView得到AnimationDrawable
?
Java代碼??3 執(zhí)行動畫
?
Java代碼???
Frame-By-Frame Animations的代碼使用方法
//實(shí)例化AnimationDrawable對象frameAnimation = new AnimationDrawable();/*裝載資源*///這里用一個(gè)循環(huán)裝載所有名字類似的資源//如"a1...........15.png"的圖片for(int i = 1; i <= 15; i++){int id = getResources().getIdentifier("a" + i, "drawable", mContext.getPackageName());//此方法返回一個(gè)可繪制的對象與特定的資源ID相關(guān)聯(lián) mBitAnimation = getResources().getDrawable(id);/*為動畫添加一幀*///參數(shù)mBitAnimation是該幀的圖片//參數(shù)500是該幀顯示的時(shí)間,按毫秒計(jì)算frameAnimation.addFrame(mBitAnimation, 500);}/*上邊用到了Resources的getIdentifier方法 方法返回一個(gè)資源的唯一標(biāo)識符,如果沒有這個(gè)資源就返回0* 0不是有效的標(biāo)識符,在說說這個(gè)方法幾個(gè)參數(shù)的含義* 第一個(gè) 就是我們的資源名稱了。* 第二個(gè) 就是我們要去哪里找我們的資源 我們的圖片在drawable 下 所以為drawable* 第三個(gè) 我們用了Context的getPackageName返回應(yīng)用程序的包名* *///設(shè)置播放模式是否循環(huán)播放,false表示循環(huán),true表示不循環(huán)frameAnimation.setOneShot(false);//設(shè)置本類將要顯示的這個(gè)動畫this.setBackgroundDrawable( frameAnimation );?
?
6 LayoutAnimationController的使用方法(與ListView結(jié)合使用為例)
什么是LayoutAnimationController
1 LayoutAnimationController用于為一個(gè)layout里面的控件,或者是一個(gè)ViewGroup里面的控件設(shè)置動畫效果
2 每一個(gè)控件都有相同的動畫效果
3 這些控件的動畫效果在不同的時(shí)間顯示出來
4 LayoutAnimationController可以在xml文件中設(shè)置,也可以在代碼中設(shè)置
?
在XML中使用LayoutAnimaionController
1 在res/anim文件夾中創(chuàng)建一個(gè)文件,名為list_anim_layout.xml
?
Xml代碼??注意到list_anim這個(gè)xml文件,其中配置了動畫效果,也就是一個(gè)動畫配置文件(見3中)
<set>
<alpha...>
</set>
2 在布局文件中為ListView添加如下配置(就是在<listview>標(biāo)簽中添加一個(gè)屬性)
android:layoutAnimation="@anim/list_anim_layout"
?
在代碼中使用LayoutAnimationController
?
Java代碼???
7 AnimationListener的使用方法
什么是AnimationListener
1 Animation是一個(gè)監(jiān)聽器
2 該監(jiān)聽器在動畫執(zhí)行的各個(gè)階段會得到通知,從而調(diào)用相應(yīng)的方法
3 主要包含下面的三個(gè)方法
onAnimationEnd(Animation animation)
onAnimationRepeat(Animation animation)
onAnimationStart(Animation animation)
?
使用方法:
animation.setAnimationListener(new XxxAnimationListener);
其中XxxAnimationListener繼承AnimationListene
在其中實(shí)現(xiàn)三個(gè)onXXX方法
轉(zhuǎn)載于:https://www.cnblogs.com/TseChiHoi/archive/2012/10/19/2690365.html
總結(jié)
以上是生活随笔為你收集整理的Android-Animations的使用大全之二:Frame Animation和其他的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最清晰细致的教程!一步步教你打造Win7
- 下一篇: android sina oauth2.