ListView Indicate more scrollable itmes

2019-07-21 04:53发布

问题:

all i want to do is When the page has more data, there should be some indication like three dots or something like that at the bottom of the page so that user will know there are more records and will scroll it

here At the bottom of the page there is no indication that there are more records. i want to add that indication signature when there are more data.

回答1:

A possible solution is to add a View (a layout with a textView or ImageView) beneath your ListView:

<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" />

The weights are important to show both components. After that, implements the listView's 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) {

    }
});

When it reaches the last line, setVisibility(View.GONE) for the bottom View. If you want to show this View again, when user scrolls up, modify the code. Of course, you can use aother layout, a textView, or something else.

UPDATE

I played with the a layout a little bit, and there is an other solution for your layout file, where the bottom View is overlaying the listView, so the removing of this textView is smooth.

<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>