Recyclerview и навигация D-pad

Я разрабатываю приложение, которое должно использовать навигацию D-pad в RecyclerView. Моя проблема в том, что хотя я установил android:focusable=true в items.xml(news_items), похоже, это не работает.

Мой вопрос: как мне реализовать навигацию D-pad в RecyclerView?

RecyclerView находится внутри следующего макета:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

         />
    <TextView
        android:id="@+id/emptyView"
        android:visibility="gone"
        tools:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=":( \n No news available"
        android:textSize="@dimen/fsn_emty_text"
        android:layout_gravity="center_vertical"
        android:gravity="center_horizontal"
        android:paddingEnd="@dimen/activity_horizontal_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingStart="@dimen/activity_horizontal_margin"
        />

</FrameLayout>

news_items.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/news_ripple"
    android:clickable="true"
    android:focusable="true"
    android:orientation="vertical"

    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.15"
                android:background="?attr/colorAccent"

                />


            <LinearLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/ni_margin"
                android:layout_weight="9"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvTitulo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:gravity="left"
                    android:textColor="?android:attr/textColorPrimary"
                    tools:text="Titulo" />

                <TextView
                    android:id="@+id/tvFecha"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                    tools:text="Fecha" />

                <TextView
                    android:id="@+id/tvPublisher"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                    tools:text="Publisher" />
            </LinearLayout>

        </LinearLayout>
    </LinearLayout>


</LinearLayout>

ОБНОВЛЕНИЕ: это порядок фокусировки, который я получаю сейчас: красный цвет - это порядок фокусировки, который я получаю сейчас, когда я щелкаю один раз с вкладки вниз, RecyclerView (весь рейклервью) получает фокус, еще один щелкните вниз, и AdMob (показан черным) получит фокус. Синяя стрелка - это то, что я хочу внутри RecyclerView

введите здесь описание изображения


person Carlos Hernández Gil    schedule 27.04.2016    source источник
comment
Вы имеете в виду, что хотите сосредоточиться на новостях, которые находятся в Recycler View, верно?   -  person Jay Rathod RJ    schedule 27.04.2016
comment
да, новые элементы — это макет каждого элемента внутри Recyclerview. Я хочу иметь возможность перемещаться по элементам в Recyclerview через крестовину   -  person Carlos Hernández Gil    schedule 27.04.2016
comment
Посмотрите здесь Мой ответ из другого сообщения.   -  person Gurgen Hakobyan    schedule 20.01.2017
comment
@CarlosHernándezGil Какое решение было в вашем случае?   -  person sam_k    schedule 10.04.2019
comment
@sam_k Добавьте это в представление переработчика, как вы можете видеть в принятом ответе: android:descendantFocusability=afterDescendants   -  person Carlos Hernández Gil    schedule 11.04.2019
comment
Я сделал, вообще не работает :(   -  person sam_k    schedule 11.04.2019
comment
@CarlosHernándezGil В моем случае фокус перемещается по элементам, но не объявляет описание контента. Как вы думаете, в чем может быть проблема?   -  person sam_k    schedule 11.04.2019


Ответы (1)


Добавление android:descendantFocusability="afterDescendants" решило мою проблему

<android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:descendantFocusability="afterDescendants"
             />
person Carlos Hernández Gil    schedule 28.04.2016
comment
И не забудьте сделать корневой вид макета вашего элемента android:focusable=true - person Gurgen Hakobyan; 20.01.2017