首页 > 解决方案 > 在recyclerview项目android中更改视图之间的焦点

问题描述

我正在为 Android TV 改编我的应用程序。

我有带有物品的 RecyclerView。每个项目包括三个 LinearLayouts。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/LLChannel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/item_touch_selector"
    android:paddingLeft="@dimen/list_item_extra_padding"
    android:paddingRight="@dimen/list_item_extra_padding"
    android:weightSum="1"
    android:orientation="horizontal"
    android:baselineAligned="false">


    <LinearLayout
        android:id="@+id/item_content"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_weight="0.8"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:paddingLeft="@dimen/abc_list_item_padding_horizontal_material"
        android:paddingRight="@dimen/abc_list_item_padding_horizontal_material"
        android:orientation="horizontal">

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LLFav"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="0.1"
        >

    </LinearLayout>
    <LinearLayout
        android:id="@+id/LLURL"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="0.1"
        >

    </LinearLayout>

</LinearLayout>

我的问题是:我可以分别关注这三个 LinearLayouts 而不是全部项目(LLChannel)焦点吗?如何?

UPD 17:12 10.07.2020:

为每个 LinearLayout 添加这些东西对我没有帮助:

android:background="@drawable/item_touch_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:nextFocusRight="@id/LLFav"

UPD 12.07.2020:有什么想法可以实现吗?

UPD 13.07.2020:这很容易。我稍后会回答我自己的问题。

标签: androidfocusandroid-linearlayoutandroid-tvd-pad

解决方案


所有的 LinearLayout 都必须再包装在一个 LinearLayout 中。


推荐阅读