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