我试图咨询documentation,但发现setScrollIndicators在那里是空的。它做了什么?
答案 0 :(得分: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();
这可能有助于更好地理解概念。我还没有尝试过,但从我的理解,如果listview的第一个元素的顶部或最后一个元素或最后一个元素的底部是不可见的,并且如果列表可以滚动(向上或向下),则相应的视图可通过调用updateScrollIndicators()方法
希望这对你有用