I. Overview
Let's look at the use of layoutanimation today.
Two. Implement
Create a new animation file
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="30%" android:animationOrder="random" android:animation="@anim/slide_right" />
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="900" /></set>
Then we use the in the ListView of the layout file
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:orientation="Vertical"android:layout_height="Match_parent"Android:paddingbottom="@dimen/activity_vertical_margin"android:paddingleft="@dimen/activity_horizontal_margin"android:paddingright="@dimen/activity_horizontal_margin"android:paddingtop="@dimen/activity_vertical_margin"> <listview android:id="@+Id/listview"Android:layout_width="Match_parent"android:layoutanimation="@anim/list_anim_layout"android:layout_height="Match_parent"android:animatelayoutchanges="true"android:scrollbars="None"> </listview></Linearlayout>
Finally, give the Java code
Public class mainactivity extends Activity { PrivateListView ListView;PrivateList data =NewArrayList (); @Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); ListView = (ListView) Findviewbyid (R.id.listview); for(inti =0;i< -; i++) {Data.add ("Yang Mi"+i); } listview.setadapter (NewMyadapter ( This, R.layout.item1,r.id.text,data)); } class myadapter extends arrayadapter<String>{ PublicMyadapter (Context context,intResourceintTextviewresourceid, list<string> objects) {Super(Context, resource, Textviewresourceid, objects); } }}
Android layoutanimation Use