Android 如何支持RecyclerView的dpad控件
我目前正在尝试将Android移动应用程序移植到Android电视。我有一个RecyclerView,它似乎在我的Android电视应用程序中正确显示。我正在使用linearLayout进行回收视图。但我似乎无法使用dpad控件在RecyclerView中导航 有什么想法吗 以下是相关的xml:Android 如何支持RecyclerView的dpad控件,android,android-recyclerview,android-tv,d-pad,Android,Android Recyclerview,Android Tv,D Pad,我目前正在尝试将Android移动应用程序移植到Android电视。我有一个RecyclerView,它似乎在我的Android电视应用程序中正确显示。我正在使用linearLayout进行回收视图。但我似乎无法使用dpad控件在RecyclerView中导航 有什么想法吗 以下是相关的xml: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<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" />
我的代码遇到的问题是将焦点放在recyclerview的第一个子项上。一旦它出现,它似乎能很好地处理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"
/>
尝试在
RecyclerView
上设置android:DegenantFocusability=“AfterDegenders”
,为您的项目布局创建根视图android:Focusability=“true”
我也遇到过类似的问题。我不知道如何转移注意力。我将尝试手动处理所有dpad输入,并基本上伪造它。我会向您汇报。@Vpd,您认为我最终为RecylcerView覆盖onKeyListener使其工作是正确的方法吗。我也有这个疑问,因为遥控器可能有很多关键事件,我们可能需要处理这些事件。当我们试图跟踪关键事件和执行操作时,它变得复杂起来。必须有一个电视应用程序的谷歌图书馆跟踪和操纵关键事件,任何想法和实施链接将有助于我的情况下,你明白了吗?谢谢你的答复。我最终覆盖了onKeyListener for RecylcerView以使其工作。哦,这也是一个可靠的计划!这里的根视图是什么意思?父视图组(布局)
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();
}
}
});