【问题标题】:Multiple horizontal RecyclerView inside NestedScrollView steal focusNestedScrollView 内的多个水平 RecyclerView 窃取焦点
【发布时间】:2018-01-19 13:24:29
【问题描述】:

实际上,我目前正在为一个 AndroidTV 应用工作。我有多个水平的RecyclerViewNestedScrollView 内从右到左,就像那张图片一样。

问题是当我向左滚动更多时,焦点会移动到不同的列表或不同的视图,这是不好的。

我不想改变焦点。如果列表到达末尾,则焦点应保持在同一位置。

我试过了:

android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true" //in parent layout

但是没有用..

谁能帮帮我吗?

未解决

【问题讨论】:

  • 尝试遵循related SO post中的解决方案
  • 已经尝试但没有帮助@Mr.Rebot
  • 我解决了在滚动视图中使用 android:descendantFocusability="blocksDescendants" 进行根布局的问题。也使用嵌套滚动视图而不是滚动视图。
  • 我还在 ScrollView 的根布局中尝试了 android:descendantFocusability="blocksDescendants" ,但是在 RecyclerView 的子项中使用焦点未检测到之后。 @asozcan
  • 只是想知道,你解决了这个问题吗?我现在面临同样的问题

标签: android android-recyclerview android-tv


【解决方案1】:

尝试将您的 ScrollView 更改为 NestedScrollView。这背后的一个原因是

**NestedScrollView**

NestedScrollView 和 ScrollView 一样,但它支持充当 新旧版本中的嵌套滚动父项和子项 安卓的。默认启用嵌套滚动。

**ScrollView**

可以滚动的视图层次结构的布局容器 用户,允许它大于物理显示器。一个滚动视图 是一个 FrameLayout,这意味着您应该在其中放置一个包含 要滚动的全部内容;这个孩子本身可能是一个布局 具有复杂对象层次结构的管理器

这将帮助您确定所关注的布局。

【讨论】:

  • 我已经使用了 NestedScrollView 但没有帮助...@Dipali shah
  • 有问题你提到你的RecyclerviewScrollView里面
【解决方案2】:

您可以使用以下结构进行嵌套滚动

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:clickable="false"
    android:orientation="vertical">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll_search_all"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="false"
                    android:nestedScrollingEnabled="false" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="false"
                    android:nestedScrollingEnabled="false" />

            </LinearLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</FrameLayout>

我希望这会有所帮助!

【讨论】:

  • 对不起,它不会改变任何东西。谢谢你的帮助.. @Alpesh Sorathiya
【解决方案3】:

尝试在您的 recycleview 第 2 部分中使用此代码:

android:layoutDirection="rtl"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 2015-12-03
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多