LayoutAnimationController可以控制一組控件按照規定顯示,有兩種方法來實現
1.下面以XML文件實現,先在res下新建anim文件夾,新建一個文件alpha.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"
>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="3000"
/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"
>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="3000"
/>
</set>
然後新建一個文件layoutanimation.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="https://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animationOrder="normal"
android:animation="@anim/alpha"
/>
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="https://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animationOrder="normal"
android:animation="@anim/alpha"
/>
在listview中使用下面代碼
[html]
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/layoutanimation"/>
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/layoutanimation"/>
這樣就完成瞭
2.代碼實現
[java]
AlphaAnimation alpha=new AlphaAnimation(0, 1);
alpha.setDuration(3000);
LayoutAnimationController lac=new LayoutAnimationController(alpha);
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
lv.setLayoutAnimation(lac);
AlphaAnimation alpha=new AlphaAnimation(0, 1);
alpha.setDuration(3000);
LayoutAnimationController lac=new LayoutAnimationController(alpha);
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
lv.setLayoutAnimation(lac);
下面是顯示的順序
LayoutAnimationController.ORDER_NORMAL; //順序顯示
LayoutAnimationController.ORDER_REVERSE;//反顯示
LayoutAnimationController.ORDER_RANDOM//隨機顯示