LayoutAnimationController can control the display of a group of controls according to regulations. There are two methods to achieve this.
1. The following is implemented using an XML file. First, create an anim folder under res to create a file alpha. xml.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator"
Android: Required interpolator = "true"
>
<Alpha
Android: fromAlpha = "0"
Android: toAlpha = "1"
Android: duration= "3000"
/>
</Set>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator"
Android: Required interpolator = "true"
>
<Alpha
Android: fromAlpha = "0"
Android: toAlpha = "1"
Android: duration= "3000"
/>
</Set>
Create a new file named layoutanimation. xml.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LayoutAnimation
Xmlns: android = "http://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 = "http://schemas.android.com/apk/res/android"
Android: delay= "0.5"
Android: animationOrder = "normal"
Android: animation = "@ anim/alpha"
/>
Use the following code in 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"/>
This completes
2. Code Implementation
[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 );
Below is the display order
LayoutAnimationController. ORDER_NORMAL; // sequential display
LayoutAnimationController. ORDER_REVERSE; // reverse display
LayoutAnimationController. ORDER_RANDOM // random display