2016-02-11 19 views
9

現在、AndroidモバイルアプリをAndroid TVに移植しようとしています。私は自分のAndroid TVアプリで正しく表示されているようなRecyclerViewを持っています。私はRecyclerViewにlinearLayoutを使用しています。しかし、私はdpadコントロールを使ってRecyclerView内をナビゲートすることはできないようです。RecyclerViewのdpadコントロールをサポートする方法

アイデア?私のコードは、問題recyclerviewの最初の子にフォーカスを与えていたをやってを持っていた何

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/RecyclerView" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left" 
    android:background="@color/nav_bg" 
    android:scrollbars="vertical" 
    tools:showIn="@layout/activity_content" /> 

+0

android:descendantFocusability="afterDescendants"を設定してみてください、あなたのxmlを投稿ファイル。 –

+0

私も同様の問題がありました。私は焦点をシフトする方法を知らない。私は手動ですべてのdpad入力を処理し、基本的にそれを試してみるつもりです。私は報告する。 –

+0

@Vpd、これを* RecylcerViewのonKeyListenerをオーバーライドして正常に動作させると思いますか?*正しい方法です。私もこの疑念を念頭に置いていました。リモコンは、このアプローチを取っている人々を処理するために必要な多くの重要な出来事を持つことができます。また、主要なイベントを追跡して操作を実行しようとすると複雑になります。キーイベントの追跡と操作のためのtvアプリ用のGoogleライブラリが必要です。あなたが考え出した場合には、あらゆるアイデアや実装リンクが役立ちますか? – DJphy

答えて

0

:ここ

が懸念xmlです。一度そこにいれば、dpadコントロールをうまく扱うように見えました。

あなたのコードをもっと見ることなく、これが最良の提案です。これが動作しない場合は、あなたの活動と完全なxmlを提供してください。がんばろう!あなたのXMLで

:あなたの活動で

 <!-- make sure this is an attribute for the layout that would 
      get focus before the recycler view --> 
     android:nextFocusDown="@+id/RecyclerView" 



    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/RecyclerView" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="left" 
     android:background="@color/nav_bg" 
     android:scrollbars="vertical" 
     tools:showIn="@layout/activity_content" 

     android:focusable="true" 
    /> 

public static final int BANNER = 0; 
    public static final int RECVIEW1 = 1; 
    public static final int RECVIEW2 = 2; 
    private static int currFocus = 0; 

    //you will need to do something similar to this listener for all focusable things 
    RecyclerView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 
       Log.i("ONFOCUSCHANGE- reclist", "focus has changed I repeat the focus has changed! current focus = " + currFocus); 
       if(currFocus != RECVIEW1){ 
        currFocus = RECVIEW1; 
        RecyclerView.getChildAt(0).requestFocus(); 
       } 
      } 
     }); 
+0

ご返信ありがとうございます。私はRecylcerViewのonKeyListenerをオーバーライドして動作させました。 – Vpd

+0

ああも確かな計画! –

2

は、あなたのアイテムのレイアウトのRecyclerView

2

メイクのルートビューにandroid:focusable="true"

関連する問題