1.设置分割线和高度
android:divider="@android:color/darker_gray"
android:dividerHeight="8dp"
设置 android:divider="@null" 可把分割线设为透明
2.隐藏ListView滚动条
android:scrollbars="none"
3.取消ListView的item点击效果
android:listSelector="@android:color/transparent"
4.设置ListView显示第几个Item
listview.setSelection(N)
setSelection方法时瞬间完成,可以使用如下代码实现平滑移动
listview.smmothScrollBy(distance,duration);
listview.smoothScrollByOffset(offset);
listview.smoothScrollToPosition(index);
5.动态修改ListView
mData.add("new");
mAdapter.notifyDataSetChanged();
6.遍历ListView中所有item
for(int i = 0 ; i <mListView.getChildCount(); i++){
View view = mListView.getChildAt(i);
}
7.ListView滑动监听
mListViw.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
//触摸时操作
break;
case MotionEvent.ACTION_MOVE:
//移动时操作
break;
case MotionEvent.ACTION_UP:
//离开时操作
break;
}
return false;
}
});
mListViw.setOnScrollListener(new AbsListView.OnScrollListener() {
@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:
//离开后ListView由于惯性继续滑动
break;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d("LOG","firstVisibleItem" + firstVisibleItem);
Log.d("LOG","visibleItemCount" + visibleItemCount);
Log.d("LOG","totalItemCount" + totalItemCount);
//滚动时一直调用
}
});