android fastScroll只涵盖了部分列表

use*_*872 19 android expandablelistview fastscroll

我有一个实现的类expandable list activity.
在XML代码中(或者我可以在java中完成),我设置fastScrollEnabledtrue.这样做可以实现快速滚动.但快速滚动仅适用于列表的顶部.就像我可以使用fastscroll拇指栏滚动整个列表,但只能在滚动条的顶部工作.它与整个列表不成比例.我可以将拇指栏拖动到列表的底部,但它不会滚动,因为listview它已经滚动到底部,因为它的奇怪行为只能在列表的顶部工作.
令我感到困惑,如果需要,我可以尝试澄清更多......

我确实实现了一个自定义 BaseExpandableListAdapter.

小智 5

我刚刚找到一种解决方法来阻止系统显示这种错误的行为.

有两种情况使用不同的代码进行SectionIndexer工作.

第一种情况是您使用FastScrollbar-Thumb导航到下一部分.假设组是您的部分,实现它的重写方法SectionIndexer将如下所示:

@Override
public int getPositionForSection(int section) {
    return section;
}

// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
    return ExpandableListView.getPackedPositionGroup(
               expandableListView
                   .getExpandableListPosition(position));
}
Run Code Online (Sandbox Code Playgroud)

第二种情况是您手动滚动列表,快速滚动条根据部分而不是所有项目移动.因此代码看起来像这样:

@Override
public int getPositionForSection(int section) {
    return expandableListView.getFlatListPosition(
               ExpandableListView.getPackedPositionForGroup(section));
}

// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
    return ExpandableListView.getPackedPositionGroup(
               expandableListView
                   .getExpandableListPosition(position));
}
Run Code Online (Sandbox Code Playgroud)

可以看出,如果没有进一步采用,这两种行为就无法发挥作用.

使其同时工作的解决方法是捕捉有人每手滚动(即通过触摸滚动)的情况.这可以通过使用OnScrollListener适配器类实现接口并将其设置为ExpandableListView:

public class MyExpandableListAdapter extends BaseExpandableListAdapter 
                 implements SectionIndexer, AbsListView.OnScrollListener {

    // Your fields here
    // ...
    private final ExpandableListView expandableListView;
    private boolean manualScroll;

    public MyExpandableListAdapter(ExpandableListView expandableListView
                                   /* Your other arguments */) {
        this.expandableListView = expandableListView;
        this.expandableListView.setOnScrollListener(this);
        // Other initializations
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        this.manualScroll = scrollState == SCROLL_STATE_TOUCH_SCROLL;
    }

    @Override
    public void onScroll(AbsListView view, 
                         int firstVisibleItem, 
                         int visibleItemCount, 
                         int totalItemCount) {}

    @Override
    public int getPositionForSection(int section) {
        if (manualScroll) {
            return section;
        } else {            
            return expandableListView.getFlatListPosition(
                       ExpandableListView.getPackedPositionForGroup(section));
        }
    }

    // Gets called when scrolling the list manually
    @Override
    public int getSectionForPosition(int position) {
        return ExpandableListView.getPackedPositionGroup(
                   expandableListView
                       .getExpandableListPosition(position));
    }

    // Your other methods
    // ...
}
Run Code Online (Sandbox Code Playgroud)

这为我解决了这个问题.


Rab*_*ant 2

这是快速滚动条中的一个错误。它不能很好地与ExpandableListView.

请参阅我的代码

(它还包括某些情况下的解决方法)