ListView指示更多可滚动的项目

时间:2012-08-21 09:52:58

标签: android listview android-listview scrollview

我想要做的就是当页面有更多数据时,应该在页面底部有一些像三个点或类似的指示,以便用户知道有更多记录并将滚动它

enter image description here

此处页面底部没有迹象表明还有更多 记录。我希望在有更多数据时添加该指示签名。

1 个答案:

答案 0 :(得分:2)

一种可能的解决方案是在ListView下面添加一个View(带有textView或ImageView的布局):

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>
<LinearLayout
    android:id="@+id/viewid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0" />

权重对于显示两个组件非常重要。 之后,实现listView的onScrollListener。

setOnScrollListener(new OnScrollListener() {
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        //get the showed item num, and if its equal to total, you can hide the view
        //get a reference to your viewid
        viewid.setVisibility(View.GONE);
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }
});

当它到达最后一行时,底部视图的setVisibility(View.GONE)。 如果要再次显示此视图,当用户向上滚动时,请修改代码。当然,您可以使用另一种布局,textView或其他内容。

<强>更新

我稍微使用了一个布局,并且你的布局文件有另一个解决方案,其中底部视图覆盖了listView,因此删除这个textView是顺利的。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="5dp"
        android:background="#ffffff"
        android:layout_alignParentBottom="true"
        android:text="..." />
</RelativeLayout>