Android: what does ListView.setScrollIndicators (up, down) do?

I tried to consult the documentation but found setScrollIndicators running there. What is he doing?

+3


source to share


1 answer


I tried searching but couldn't find any documentation. But looking at the source of AbsListView I found the following

 View mScrollUp;
 View mScrollDown;

 public void setScrollIndicators(View up, View down) {
    mScrollUp = up;
    mScrollDown = down;
}


void updateScrollIndicators() {
    if (mScrollUp != null) {
        boolean canScrollUp;
        // 0th element is not visible
        canScrollUp = mFirstPosition > 0;

        // ... Or top of 0th element is not visible
        if (!canScrollUp) {
            if (getChildCount() > 0) {
                View child = getChildAt(0);
                canScrollUp = child.getTop() < mListPadding.top;
            }
        }

        mScrollUp.setVisibility(canScrollUp ? View.VISIBLE : View.INVISIBLE);
    }

    if (mScrollDown != null) {
        boolean canScrollDown;
        int count = getChildCount();

        // Last item is not visible
        canScrollDown = (mFirstPosition + count) < mItemCount;

        // ... Or bottom of the last element is not visible
        if (!canScrollDown && count > 0) {
            View child = getChildAt(count - 1);
            canScrollDown = child.getBottom() > mBottom - mListPadding.bottom;
        }

        mScrollDown.setVisibility(canScrollDown ? View.VISIBLE : View.INVISIBLE);
    }
}

      

Here mListPadding



   Rect mListPadding = new Rect();

      

This can help you better understand the concept. I have not tried this yet, but from my understanding, if the top item of the first item in the list or the bottom item of the last item or last item is not visible, and if the list can be scrolled (up or down), then the corresponding view becomes visible by calling the updateScrollIndicators () method

Hope this is helpful for you.

+2


source







All Articles