Car*_*Gil 2 android d-pad android-recyclerview
我正在开发一个需要使用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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
更新:这是我现在收到的焦点顺序:红色是我现在获得的焦点顺序,当我从标签向下单击一次时,RecyclerView(整个reycclerview)获得焦点,再一次点击向下,AdMob(以黑色显示)获得焦点.我想在RecyclerView中使用蓝色箭头
添加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"
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2849 次 |
| 最近记录: |