Vpd*_*Vpd 10 android d-pad android-tv android-recyclerview
我目前正在尝试将Android移动应用移植到Android TV.我有一个似乎在我的Android TV应用程序中正确显示的RecyclerView.我正在使用linearLayout作为我的RecyclerView.但我似乎无法使用dpad控件在RecyclerView中导航.
有任何想法吗?
这是有关的xml:
<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" />
Run Code Online (Sandbox Code Playgroud)
我的代码遇到问题的是将焦点集中在 recyclerview 的第一个子级上。一旦它在那里,它似乎可以很好地处理方向键控制。
在没有看到更多代码的情况下,这是最好的建议。如果这不起作用,请提供您的活动和完整的 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"
/>
Run Code Online (Sandbox Code Playgroud)
在您的活动中:
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();
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3938 次 |
| 最近记录: |