为列表添加布局动画效果

给列表ListView添加动画效果,首先MainActivity继承自ListView,通过setLayoutAnimation传一个LayoutAnimationController,就可以设置ListView的动画效果。
public class MainActivity extends ListActivity {

private ArrayAdapter adapter;
private LayoutAnimationController lac;
private ScaleAnimation sa;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    adapter = new ArrayAdapter(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);

}

}

你可能感兴趣的:(为列表添加布局动画效果)