Android graphic image and animation (v) layoutanimationcontroller detailed _android

Source: Internet
Author: User
Tags stub

First of all, we need to introduce the following layoutanimationcontroller:

* 1.LayoutAnimationController is used for a layout inside the control, or a viewgroup
* Inside the control set animation effect (that is, the entire layout)
* 2. Each control has the same animation effect
* 3. The animation effects of these controls are displayed in different implementations
* 4.LayoutAnimationController can be set in an XML file or set in code

In this paper, the two methods for implementing Layoutanimationcontroller are introduced respectively:

One, implement in XML file

The steps are shown in the following illustration:



Here is an example of how to implement this:

An example of an implementation is to click on the "Test" button, which shows an animated view showing the screenshot as follows:


the specific implementation process is as follows :

Requires two animated XML files:

1.list_item_layout

Copy Code code as follows:

<layoutanimation xmlns:android= "Http://schemas.android.com/apk/res/android"
android:animation= "@anim/list_item_alpha"
Android:animationorder= "Normal"
android:delay= "0.8"/>

2.list_item_alpha
Copy Code code as follows:

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<alpha
Android:fromalpha= "0.0"
Android:toalpha= "1.0"
Android:duration= "2000"
/>
</set>

3. The following instructions need to be added to the ListView
Copy Code code as follows:

android:layoutanimation= "@anim/list_item_layout"

The specific implementation code is as follows:
Copy Code code as follows:

public class Layoutanimation_activity extends activity {
Private button button;
Private Button button2;
Private ListView ListView;
private static final string[] strings={"Brucezhang", "Alhpa", "Translate", "Blanklin", "Rotate",
"Greenfrank"};

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_layout_animation_);
button= (Button) Findviewbyid (R.id.button);
Button2= (Button) Findviewbyid (R.id.button2);
listview= (ListView) Findviewbyid (R.id.listview);
Final arrayadapter<string> adapter=new arrayadapter<string> (This, r.layout.item_list, STRINGS);
Button.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Listview.setadapter (adapter);
}
});
Button2.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Listview.setadapter (NULL);
}
});
}


@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.activity_layout_animation_, menu);
return true;
}

}

Two, implement Layoutanimationcontroller in Java code

The steps to implement are as follows:


The code used in this example is as follows :

Copy Code code as follows:

Animation animation=animationutils.loadanimation (Layoutanimation_activity.this,
R.anim.list_item_alpha);
Layoutanimationcontroller lacontroller=new Layoutanimationcontroller (animation);
Lacontroller.setorder (Layoutanimationcontroller.order_normal);
Listview.setlayoutanimation (Lacontroller);

Related Article

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.