【问题标题】:How to move focus from RowsSupportFragment's row to next layout component?如何将焦点从 RowsSupportFragment 行移动到下一个布局组件?
【发布时间】:2020-02-08 12:59:17
【问题描述】:

我正在使用 Android Leanback 库来创建电视应用程序。我有一个扩展片段(即 RowsSupportFragment)的布局,下面有一个按钮。因此,当我在到达最后一个项目后向下滚动到 RowsSupportFragment 中的项目列表时,焦点不会转到按钮。 我已经尝试过设置 focusable(true)、nextFocusDown(buttonId) 等。

我可以看到 RowsSupportFragment 在内部使用 VerticalGridView 来扩充项目列表。

有人知道吗?

这是我的布局:

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<FrameLayout
android:id="@+id/listviewFragmentId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:nextFocusDown="@id/nextButtonId"
android:nextFocusForward="@id/nextButtonId" 
layout_constraintBottom_toTopOf="@id/nextButtonId"/>

<Button
android:id="@+id/nextButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:focusable="true"
android:text="Hello Next"/>

<// other items>
</android.support.constraint.ConstraintLayout>

注意: 如果我左/右对齐按钮,焦点可以正常工作。

【问题讨论】:

标签: android android-layout android-constraintlayout android-tv leanback


【解决方案1】:

在我的情况下,当我需要专注于任何视图时,这是可行的

view.requestFocus();

【讨论】:

  • 问题是,因为焦点在 VerticalGridView 项目内,所以要么我检查焦点到最后一个项目,而不是我必须请求关注 RowsSupportFragment 之外的按钮(意味着在活动级别)
【解决方案2】:

在我的情况下,我需要关注 RowSupportFragment 项目外的任何视图,因此使用 Leanback 样式中的 focusOutEnd、focusOutFront 和其他焦点功能解决了我的解决方案。 就像从 RowSupportFragment 向外部 Button 小部件请求焦点一样,设置 &lt;item name="focusOutEnd"&gt;true&lt;/item&gt; 风格对我有用。

【讨论】:

    猜你喜欢
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多