1. By adding Java code , the resource file is basically not modified
XML file, just add a ListView and do not paste the code of the XML file.
Java code:
1 Public classMainactivityextendsActivity {2 3 @Override4 protected voidonCreate (Bundle savedinstancestate) {5 Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7 8Scaleanimation sa=NewScaleanimation (0, 1, 0, 1);9Sa.setduration (1000);TenLayoutanimationcontroller lac=NewLayoutanimationcontroller (SA, 0.5f); One Lac.setorder (layoutanimationcontroller.order_reverse); A -ListView lv=(ListView) Findviewbyid (r.id.lv); -Arrayadapter<string> adapter=NewArrayadapter<string> (Getapplicationcontext (), Android. R.layout.simple_list_item_1,Newstring[]{"Beijing", "Xian", "Shanghai", "Nanjing"}); the Lv.setadapter (adapter); - Lv.setlayoutanimation (LAC); - } -}
2. Add animation effects through a resource file
To create a new Android XML fils, on the new page, Resource type selected for tween animation,root element is selected as Alpha. (You can also set multiple animation effects together)
Scale_anim.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 < Scalexmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:fromxscale= "0"4 Android:toxscale= "1"5 Android:fromyscale= "0"6 Android:toyscale= "1"7 android:duration= "+">8 </ Scale>
Create a new Android XML fils
Listview_anim.xml
1 <? xml version= "1.0" encoding= "Utf-8" ?> 2 xmlns:android 3 Android:animation = "@anim/scale_anim" 4 Android:delay = "0.5" 5 </ layoutanimation >
In the Main-activity.xml file, set the properties of the ListView
1 < android:id= "@+id/lv"2 android:layout_width= "Match_parent "3 android:layout_height=" Match_parent "4 Android:layoutanimation= "@anim/listview_anim"></listview>
Android development for ListView set layout animation effect