在recyclerview项目android中更改视图之间的焦点

Posted

技术标签:

【中文标题】在recyclerview项目android中更改视图之间的焦点【英文标题】:Changing focus between views in recyclerview item android 【发布时间】:2020-10-31 04:45:57 【问题描述】:

我正在为 android TV 改编我的应用。

我有带有项目的 RecyclerView。每个项目包含三个 LinearLayout。

<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_
    android:layout_
    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_
        android:layout_
        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_
        android:layout_
        android:layout_gravity="center"
        android:layout_weight="0.1"
        >

    </LinearLayout>
    <LinearLayout
        android:id="@+id/LLURL"
        android:layout_
        android:layout_
        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:这很简单。我稍后会回答我自己的问题。

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于在recyclerview项目android中更改视图之间的焦点的主要内容,如果未能解决你的问题,请参考以下文章