【问题标题】:How to scroll clicked row of Android GridLayoutManager to top of RecyclerView如何将单击的 Android GridLayoutManager 行滚动到 RecyclerView 的顶部
【发布时间】:2016-10-05 14:28:11
【问题描述】:

我正在使用带有 GridLayoutManager 的 RecyclerView,我需要将点击的视图滚动到 RecyclerView 的顶部,但是使用内置的 mRecyclerView.scrollToPosition(0); 方法什么也没做,即使使用处理程序来延迟滚动行为,也有有人能做到吗?

【问题讨论】:

    标签: android android-recyclerview gridlayoutmanager


    【解决方案1】:

    您应该尝试布局管理器的 scrollToPositionWithOffset(position, offset) 方法。 这对我有用:

    layoutManager.scrollToPositionWithOffset(position, 0);
    

    offset 参数是项目视图的起始边缘和 RecyclerView 的起始边缘之间的距离(以像素为单位)。

    【讨论】:

    • 这似乎不适用于 GridLayoutManager,看起来只有 LinearLayoutManager 可以这样做:/
    • 我使用 GridLayoutManager,它对我有用。 recyclerview-v7:24.2.1.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多