一、ListView的分割线
方法1.ListView中每个Item项之间都有分割线,设置android:footerDividersEnabled表示是否显示分割线,此属性默认为true。
1.不显示分割线只要在ListView控件中添加android:footerDividersEnabled="false"即可。
<ListView
android:id="@+id/local_groups_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="false" />
2.改变ListView的分割线颜色和宽度,需要在布局中定义android:divider和android:dividerHeight属性。
<ListView
android:id="@+id/local_groups_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/divider_color"
android:dividerHeight="1px" />
方法2.ListView中每个Item项的布局中,添加一条横线。(更推荐用第二种,因为当ListView调用AddFootView()添加底部View的时候,用上边的方法会默认为底部的View添加一条横向的分割线,当ListView的数据为空或者不足的时候,ss会影响效果)。
二、ListView加载更多数据
1.添加底部view布局,向下滑动到底部的时候,加载更多数据。
底部view的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="30dp" >
<TextView
android:id="@+id/tv_loadingmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="没有数据"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
在Activity中的添加,并为ListView添加滑动监听事件。
footView = LayoutInflater.from(this).inflate(R.layout.loading_more,
null);
tv_loadingmore = (TextView) footView.findViewById(R.id.tv_loadingmore);
tv_loadingmore.setVisibility(View.GONE);
// listview的addFooterView()添加view到listview底部一定要加在listview.setAdapter(adapter);这代码前面
lv_gongdan.addFooterView(footView);
lv_gongdan.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// 滑到底部后自动加载,判断listview已经停止滚动并且最后可视的条目等于adapter的条目
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE
&& lastVisibleIndex == gdAdapter.getCount()) {
// 加载更多数据
if (lv_gongdan.getAdapter().getCount() >= pSize) {
tag = 1;
tv_loadingmore.setText("加载更多数据");
tv_loadingmore.setVisibility(View.VISIBLE);
initData();
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// 计算最后可见条目的索引
lastVisibleIndex = firstVisibleItem + visibleItemCount - 1;
}
});