Layout animations in Android

Source: Internet
Author: User

Brief introduction

Layout animations are animations to layouts that affect the layout of sub-objects

How to use

To animate a layout:

Find the ID of the layout you want to set, create a layout animation, create a layoutanimationcontroller, pass the animation to it, and finally set the LAC for this layout.

The duration of the SA is the time the entire layout animation is completed, and the delay of the LAC refers to the time between each sub-object.

        LinearLayout layout = (linearlayout) Findviewbyid (r.id.activity_main);         New Scaleanimation (0, 1, 0, 1);        Sa.setduration (+);         New Layoutanimationcontroller (SA, 0.5f);        Layout.setlayoutanimation (LAC);

Layout content Changes Animation:

By setting the Animatelayoutchange property of the layout, you can animate when the content of your layouts changes.

To add a layout animation to a list:

Like animating a layout, you just need to create a LAC and set it to list.

public class Mainactivity extends Listactivity {
Private arrayadapter<string> adapter;
Private Layoutanimationcontroller Lac;
Private Scaleanimation sa;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
adapter = new Arrayadapter<string> (this, Android. R.layout.simple_list_item_1, new string[]{"Hello", "World", "!"});
Setlistadapter (adapter);
SA = new Scaleanimation (0, 1, 0, 1);
Sa.setduration (1000);
Lac = new Layoutanimationcontroller (SA, 0.5f);
Getlistview (). Setlayoutanimation (LAC);
}
}

You can also configure animations for layouts through XML:

First create the Scale.xml:

<android:fromxscale= "0"       android:toxscale= "1"        Android:toyscale= "1"       android:fromyscale= "0"       android: Duration="       xmlns:android"= "http://schemas.android.com/apk/res/ Android "></scale>

Then create the layoutanimation:

<android:animation= "@anim/scale"                 android:delay= "0.5"                  xmlns:android= "http://schemas.android.com/apk/res/android"></  layoutanimation>

Finally, you can specify Layoutanimation in the component of the layout:

< ListView             Android:id = "@android: Id/list"             android:layoutanimation= "@anim/listview_anim"            android:layout_width= " Match_parent "            android:layout_height=" Match_parent "></  ListView>

Layout animations in Android

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.