我的活动包含两个垂直分离的片段。
左侧片段包含ListView
,其中包含五个不同的类别。右侧片段显示与类别对应的内容。
右侧片段包含RecyclerView
,其中包含多个自定义视图(图标和字符串标签)。
问题是我在左片段(列表视图的第一个元素)中的第一个选项,然后按向右导航键然后正确聚焦转移到右片段的第一个自定义视图。但是当我使用非第一个选项时,焦点不会转移到自定义视图,而是转移到回收器视图。
我正在为每个自定义视图设置 setFocusable 和 onFocusChangeListener 属性。
那么有人可以告诉我缺少什么吗?
编辑代码段:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="20">
<FrameLayout
android:id="@+id/left_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"/>
<FrameLayout
android:id="@+id/right_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="15"
android:background="@color/lightBlue" />
</LinearLayout>
RecyclerView适配器代码段:
drawable = holder.itemView.getBackground();
holder.itemView.setFocusable(true);
holder.itemView.setOnFocusChangeListener(focusChangeListener);
片段边栏:
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:divider="@android:color/transparent"
android:scrollbars="none"/>
ListView ArrayAdapter代码段:
convertView.setTag(categoryClass)
categoryClass包含两个元素图标和标签。