【问题标题】:RecyclerView automatically scrolls to the bottom of the list d-padRecyclerView 自动滚动到列表底部 d-pad
【发布时间】:2019-05-08 14:07:09
【问题描述】:

我有一个问题,如果 RecyclerView 有很多项目(超过 180 个),当我在第一行单击 D-PAD Down 时,用户会自动向下滚动到列表底部。我正在为这个列表使用 GridLayout。

这是我的自定义回收站视图onDispatchEvent()

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
   return super.dispatchKeyEvent(event);
}

这里是视图:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:id="@+id/entry_container"
        android:descendantFocusability="beforeDescendants"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CustomRecycleView
            android:id="@+id/list_view_horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/row_title"
            android:layout_marginLeft="@dimen/margin_filter"
            android:layout_marginRight="@dimen/margin_filter" />
   </RelativeLayout>
</layout>

加载大约 120-130 个项目时不会出现此问题。有没有人遇到过这种类型的自动滚动?

【问题讨论】:

    标签: android android-recyclerview d-pad


    【解决方案1】:
    recyclerView.scrollToPosition(List.size - 1)
    

    就我而言,上面的代码对我有用。它会自动将屏幕滚动到列表中添加的最后一项。

    【讨论】:

    • 嗨,我不想让它滚动到底部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2016-11-13
    • 2016-09-15
    • 2018-08-21
    相关资源
    最近更新 更多