首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android fastScroll只涵盖了列表的一部分。

android fastScroll只涵盖了列表的一部分。
EN

Stack Overflow用户
提问于 2010-12-16 22:31:49
回答 2查看 3.2K关注 0票数 19

我有一个实现expandable list activity的类。

在XML代码中(或者我可以在java中这样做),我将fastScrollEnabled设置为true。这确实可以实现快速滚动。但是快速滚动只适用于列表的顶部。例如,我可以使用快速滚动拇指条来滚动整个列表,但只在滚动条的顶部有效。它与整个列表不成比例。我可以拖动拇指条到列表的底部,但它不会滚动,因为listview已经滚动到底部,因为它的奇怪行为只在列表的顶部工作。

令人困惑的是,我知道,如果需要,我可以尝试澄清更多....

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

EN

回答 2

Stack Overflow用户

发布于 2013-06-24 22:26:04

我刚刚找到了一种解决方法,可以防止系统显示这种错误行为。

有两种情况使用不同的代码使SectionIndexer工作。

第一个场景是使用FastScrollbar-Thumb导航到下一节。假设组是您的部分,用于实现SectionIndexer的覆盖方法将如下所示:

代码语言:javascript
复制
@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));
}

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

代码语言:javascript
复制
@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));
}

可以看出,如果没有进一步的采用,这两种行为就不能一起发挥作用。

让两者都工作的变通方法是,当有人用手滚动(即通过触摸滚动)时,捕捉到这种情况。这可以通过使用适配器类实现OnScrollListener接口并将其设置到ExpandableListView上来完成

代码语言:javascript
复制
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
    // ...
}

这就为我修复了bug。

票数 5
EN

Stack Overflow用户

发布于 2012-04-29 20:47:21

这是快速滚动中的一个错误。它不能很好地与ExpandableListView配合使用。

参见my code

(它还包括某些情况下的变通方法)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4461804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档