1.设置项目间分割线:(红色,高10dp)
android:divider="@android:color/red"
android:dividerHeight="10dp"
2.不显示分隔线:
android:divider="@null"
3.隐藏ListView滚动条:
android:scrollbars="null"
4.取消ListView的item点击效果:
android:listSelector="#00000000"
或者android:listSelector="@android:color/transparent"
5。设置ListView显示第N个item:
listView.setSelection(N);
6.listView的动态修改:
mAdapter.notifyDataSetChanged();
7.遍历所有的item:
for(int i=0;i<listView.getChildCount();i++){
View view = listView.getChildAt(i);
}
8.处理空ListView
然后,listView.setEmptyView()findViewById(R.id.empty_view);
9.关于listView的滑动
ListView list;
list.setOnScrollListener(new AbsListView.OnScrollListener() {
int lastVisibleItemPosition;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState){
case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
//滑动停止时
break;
case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
//正在滚动时
break;
case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
//手指抛动
break;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//滚动时一直在调用
if(firstVisibleItem+visibleItemCount==totalItemCount&&totalItemCount>0){
//滚动到最后一行
}
if(firstVisibleItem>lastVisibleItemPosition){
//上滑
}
if(firstVisibleItem<lastVisibleItemPosition){
//下滑
}
lastVisibleItemPosition=firstVisibleItem;
}
});