LayoutAnimationController for Android animation (5)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.