- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此处 VerticalGridView(VG) 将填充一些数据。 VG 在向上/向下按 D-PAD 键时获得焦点,它工作正常。但问题是当焦点位于网格中的第零项并且用户按下 D-PAD keyup 焦点必须设置为 VG 之外的 View 之一,即 ll_exit(xml 文件中提到的 id),但当前焦点不是去上述观点。请告诉我如何解决这个问题。
我尝试设置 android:nextFocusUp="@id/ll_exit"但它没有移动并尝试在事件级别实现 onKeyUp 方法,如下所示
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
Log.d(TAG, "onKeyUp: " + event.getAction());
GenresFragment fragment = (GenresFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_genre);
int pos = fragment.getVerticalGridView().getSelectedPosition();
if (pos == 0) {
fragment.getLlExit().requestFocus();
}
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
但这里的问题是当我在 VG 中的第一个项目并突然按下向上键按钮时,它会转到我需要聚焦的 View 。即xml文件中的ll_exit View
<b>main_layout.xml</b>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_toolbar"
android:layout_width="@dimen/select_genre_fragment_width"
android:layout_height="@dimen/select_genre_toolbar_height"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_all_channels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/ll_genres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/ll_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<android.support.v17.leanback.widget.VerticalGridView
android:id="@+id/vg_genres"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ll_toolbar"
android:nextFocusUp="@id/ll_exit" />
</RelativeLayout>
最佳答案
尝试将以下 XML 属性添加到 VG
app:focusOutEnd="true"
app:focusOutFront="true"
它对我有用!
关于gridview - VerticalGridView 的焦点处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55830012/
此处 VerticalGridView(VG) 将填充一些数据。 VG 在向上/向下按 D-PAD 键时获得焦点,它工作正常。但问题是当焦点位于网格中的第零项并且用户按下 D-PAD keyup 焦点
此处 VerticalGridView(VG) 将填充一些数据。 VG 在向上/向下按 D-PAD 键时获得焦点,它工作正常。但问题是当焦点位于网格中的第零项并且用户按下 D-PAD keyup 焦点
我终于成功地将 android 支持库中的 VerticalGridView 添加到我的项目中。现在的问题是网格水平和垂直滚动! 这是我的来源: 和java代码: mRecyclerView = (
通过将焦点保持在中心元素上来滚动 VerticalGridView。我正在实现一个包含 1 列的 verticalgridview,我想将焦点放在位于中心的单个项目上并移动 verticalgridv
我想将 Leanback 库的详细信息屏幕中的 Row 实现到自定义屏幕中。该行将是下面的行。我已经实现了 HorizontalGridView 并设法让项目显示出来。 我的布局: 我的Java
我在玩 leanback 库,我可以看到 leanback 包中的大部分 RowsFragment,它们正在使用 HorizontalGridView 或 VerticalGridView,但是当
我是一名优秀的程序员,十分优秀!