Search code examples
androidfocusandroid-linearlayoutandroid-tvd-pad

Changing focus between views in recyclerview item android


I am doing adaptation of my app for Android TV.

I have RecyclerView with items. Each item includes three 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>

My question is: can I focus these three LinearLayouts separately instead of full item (LLChannel) focus? How?

UPD 17:12 10.07.2020:

Adding this stuff for each LinearLayout didn't help me:

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

UPD 12.07.2020: Any ideas how it would be reached?

UPD 13.07.2020: This was easy. I will answer on my own question later.


Solution

  • All of LinearLayouts must be wraped in one more LinearLayout.