TV上下方向键不能用于Appbarlayout下面的Recyclerview(Recyclerview无法使用dpad获取焦点)

3
我在Appbarlayout下有一个RecyclerView,我在appbarlayout中有一个工具栏,它正在获取焦点。我想使用Dpad控制来导航RecyclerView,但我无法做到。非常感谢任何帮助。
我尝试设置android:focusable="true",但没有成功。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground"
    android:orientation="vertical">

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/tab_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/tab_appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="true">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="3dp"
                android:scrollbars="none"
                android:focusable="true"
                android:descendantFocusability="afterDescendants"
                android:scrollingCache="true" />

        </RelativeLayout>

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>


2
RecyclerView及其父RelativeLayout不应该是“可聚焦”的。子项视图应该是可聚焦/可点击的。 - ataulm
1
您能否添加一个答案来解释问题是什么,以及您进行了哪些更改来修复它? - ataulm
1个回答

5

我没有让RecyclerView及其父级RelativeLayout具有焦点,而是让项目视图RelativeLayout具有焦点,这样就解决了问题。感谢ataulm的帮助 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接