1.res下新建anim,其下两个xml文件,list_anim负责编写动画动作,这里是一个淡入的效果;list_anim_layout负责一组对象彼此的动画顺序,间隔时间,依照哪个animation来实现动画动作。
android:delay="2"
android:animationOrder="random"
android:animation="@anim/list_anim"
2.layout下,main里面一个listview。一个button ;
item中负责list中的成员布局。
<TextView android:id="@+id/Name" android:layout_width="180dip"
android:layout_height="30dip" android:textSize="5pt"
android:singleLine="true" />
<TextView android:id="@+id/Sex" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:textSize="5pt"
android:singleLine="true"/>
3.animation.java中:
private ListAdapter buildListAdapter(){
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> m1 = new HashMap<String,String>();
m1.put("Name", "小鬼");
m1.put("Sex", "T");
HashMap<String,String> m2 = new HashMap<String,String>();
m2.put("Name", "修满");
m2.put("Sex", "P");
HashMap<String,String> m3 = new HashMap<String,String>();
m3.put("Name", "王爷");
m3.put("Sex", "T");
HashMap<String,String> m4 = new HashMap<String,String>();
m4.put("Name", "梦姑");
m4.put("Sex", "P");
list.add(m1);
list.add(m2);
list.add(m3);
list.add(m4);
SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
R.layout.item, new String[]{"Name","Sex"},
new int[]{R.id.Name,R.id.Sex});
return simpleAdapter;
listView.setAdapter(buildListAdapter());
两种控制一系列成员动画动作的方法
一。在main.xml中的ListView中添加一行
android:layoutAnimation="@anim/list_anim_layout"
即,ListView中的成员,按照anim/list_anim_layout中的设置来实现动画动作
二。在ButtonListener的onClick方法中自行编写动画效果
Animation animation = (Animation)AnimationUtils.loadAnimation(animation.this, R.anim.list_anim);
LayoutAnimationController lac = new LayoutAnimationController(animation);
lac.setOrder(LayoutAnimationController.ORDER_RANDOM);
lac.setDelay(0.5f);
listView.setLayoutAnimation(lac);
代码