我正在开发一个应用程序,需要在RecyclerView中使用D导航。我的问题是,虽然我在android:focusable=true中设置了items.xml(news_items),但它似乎不起作用。
我的问题是:如何在RecyclerView**?**中实现D-pad导航?
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(整个reycclerview)得到焦点,再单击一次,AdMob(黑色显示)得到焦点。蓝色箭头是我在RecyclerView里面想要的

发布于 2016-04-28 11:16:48
添加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"
/>https://stackoverflow.com/questions/36887573
复制相似问题