ListView回到Header位置 android开发教程

让ListView回到Header位置或者Footer位置,还有第一项元素位置,这个要是使用
ListView.setSelection(pos);

是不生效的,要换一个方法

ListView.setSelectionFromTop(0, 0);//回到ListView的header
ListView.setSelectionFromTop(1, 0);//回到第一项元素
回到footer根据具体情况而定,因为header会占一个索引值。


int postion=ListView.getAdapter().getCount();//有header的情况下
ListView.setSelectionFromTop(postion,0);


用getChildAt(0)!=null&&getChildAt(0).getTop()==0来判断是否滚动到header头最上面

猜你喜欢

转载自iaiai.iteye.com/blog/2035763