2016-04-27 13 views
0

私はRecyclerviewでDパッドナビゲーションを使用する必要があるアプリケーションを開発しています。私の問題は、items.xml(news_items)にアンドロイド:focusable = trueを設定しても動作しないようです。私の質問は:RecyclervierでD-padナビゲーションを実装する方法は? ありがとうございます。RecyclerviewとDパッドナビゲーション

<?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> 

UPDATE: 赤色フォーカス順序がある:これは今受信フォーカス順序I'amある

Reclyclerは、次のレイアウト内にあります私は今、タブから一度クリックするとRecyclerview(reycclerview全体)がフォーカスを取得し、もう一度クリックしてAdMob(黒で表示)がフォーカスを取得します。青い矢印は、私はアンドロイドの追加RecyclerView

enter image description here

+0

を解決しました「そう? –

+0

はい、新しいアイテムはRecyclerview内の各アイテムのレイアウトです。 D-padを通してRecyclerviewのアイテムをトラバースできるようにしたい –

+0

ここをクリック[別の投稿からの私の回答](http://stackoverflow.com/questions/35330058/how-to-support-dpad-controls- for-recyclerview/41763188#41763188) –

答えて

5

の内側に何をしたいです:descendantFocusability =「afterDescendantsは、」あなたは `リサイクラービューにあるニュース項目を集中したい意味私の問題

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

そしてあなたのアイテムレイアウトのルートビューを作ることを忘れないでくださいandroid:focusable = "true" –