安卓:ListView.setScrollIndicators(up, down) 是什么作用?

3

我试图查看文档,但是没有找到setScrollIndicators的具体内容。它有什么作用?


暂无文档。 - Govil
1个回答

2

我尝试搜索但找不到相关文档。 但是在查看AbsListView源代码时,我发现以下内容:

 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);
    }
}

这里的 mListPadding 是指:
   Rect mListPadding = new Rect();

这可能有助于更好地理解概念。我还没有尝试过,但据我理解,如果列表视图的第一个元素的顶部或最后一个元素的底部或最后一个元素不可见,并且列表可滚动(向上或向下),则通过调用updateScrollIndicators()方法可以使相应的视图可见。
希望这对您有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接