给列表ListView添加动画效果,首先MainActivity继承自ListView,通过setLayoutAnimation传一个LayoutAnimationController,就可以设置ListView的动画效果。
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","jikexueyuan"});
setListAdapter(adapter);
sa = new ScaleAnimation(0,1,0,1);
sa.setDuration(1000);
lac = new LayoutAnimationController(sa,0.5f);
getListView().setLayoutAnimation(lac);
}
}