【问题标题】:Android ListView scroll to top without highlighting first itemAndroid ListView 滚动到顶部而不突出显示第一项
【发布时间】:2015-08-09 17:39:07
【问题描述】:

我使用list.setSelection(0);ListView 滚动到顶部,但不幸的是,这也设置了顶部列表项的突出显示颜色。

我只想让它滚动到顶部而不是设置突出显示颜色。 (Android API 10)

【问题讨论】:

    标签: android android-listview highlight


    【解决方案1】:

    你可以使用smoothScrollToPositionFromTop

    试试

    list.smoothScrollToPositionFromTop(0, 0);
    

    list.smoothScrollToPositionFromTop(list.getHeaderViewsCount(), 0);
    

    如果您的 ListView 有标题。

    【讨论】:

    • smoothScroll 也不幸地突出了顶部的项目。
    【解决方案2】:

    你可以试试

    list.smoothScrollBy(0, 1000);
    

    if (!ListView.isStackFromBottom()) {
        ListView.setStackFromBottom(true);
    }
    ListView.setStackFromBottom(false);
    

    【讨论】:

    • 请解释为什么这些解决方案会起作用/它们做了什么,而不是仅仅建议它们。
    猜你喜欢
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 2023-02-19
    • 1970-01-01
    • 2021-02-23
    • 2017-01-25
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多