什麼是LayoutAnimationController
1 LayoutAnimationController用於爲一個layout裏面的控件,或者是一個ViewGroup裏面的控件設置動畫效果
2 每一個控件都有相同的動畫效果
3 這些控件的動畫效果在不同的時間顯示出來
4 LayoutAnimationController可以在xml文件中設置,也可以在代碼中設置
在XML中使用LayoutAnimaionController
1 在res/anim文件夾中創建一個文件,名爲list_anim_layout.xml
- <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
- android:delay="0.5"
- android:animationOrder="random"
- android:animation="@anim/list_anim" />
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animationOrder="random"
android:animation="@anim/list_anim" />
注意到list_anim這個xml文件,其中配置了動畫效果,也就是一個動畫配置文件(見5中)
<set>
<alpha...>
</set>
2 在佈局文件中爲ListView添加如下配置(就是在<listview>標籤中添加一個屬性)
android:layoutAnimation="@anim/list_anim_layout"
在代碼中使用LayoutAnimationController
- 1 創建一個Animation對象:
- 可以通過裝載xml,也可以直接使用Animation的構造函數創建Animation對象
- 2 創建LayoutAnimationController對象
- LayoutAnimationController lac=new LayoutAnimationController(animation);
- 3 設置控件顯示順序
- lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
- 4 爲ListView設置LayoutAnimationController屬性:
- listView.setLayoutAnimation(lac);
1 創建一個Animation對象:
可以通過裝載xml,也可以直接使用Animation的構造函數創建Animation對象
2 創建LayoutAnimationController對象
LayoutAnimationController lac=new LayoutAnimationController(animation);
3 設置控件顯示順序
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
4 爲ListView設置LayoutAnimationController屬性:
listView.setLayoutAnimation(lac);
AnimationListener的使用方法
什麼是AnimationListener
1 AnimationListener是一個監聽器
2 該監聽器在動畫執行的各個階段會得到通知,從而調用相應的方法
3 主要包含下面的三個方法
onAnimationEnd(Animation animation)
onAnimationRepeat(Animation animation)
onAnimationStart(Animation animation)
使用方法:
animation.setAnimationListener(new XxxAnimationListener);
其中XxxAnimationListener繼承AnimationListene
在其中實現三個onXXX方法