NestedScrollView中的多个水平RecyclerView抢占焦点

15

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

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

我不希望焦点改变。如果列表到达结尾,则焦点应保持在相同位置。

我尝试过:

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

但是它没有起作用...

有人可以帮我吗??

输入图像描述

未解决


尝试按照这个相关的 Stack Overflow 帖子中的解决方案。 - Mr.Rebot
已经尝试过了,但是 @Mr.Rebot 没有提供帮助。 - Puspak Ghosh
我通过在ScrollView的根布局中使用android:descendantFocusability="blocksDescendants"以及使用NestedScrollView代替ScrollView解决了我的问题。 - asozcan
我也尝试了在ScrollView的根布局中使用android:descendantFocusability="blocksDescendants",但是在使用后它不能检测到RecyclerView子项中的焦点。@asozcan - Puspak Ghosh
1
不知道你解决了这个问题吗?我现在也遇到了同样的问题。 - A. N
一点也不,但我们可以说解决了80%的问题。按照以下步骤进行:
  1. 将ScrollView作为根元素
  2. 在该根元素中使用以下属性 android:focusable="false" android:focusableInTouchMode="false" android:descendantFocusability="blocksDescendants"
  3. 在子布局的根元素中使用以下属性 android:clickable="true" android:focusable="true"
按照这些步骤操作并让我知道结果... @Kyk
- Puspak Ghosh
3个回答

0
尝试将您的ScrollView更改为NestedScrollView。这背后的原因是:
**NestedScrollView**

NestedScrollView与ScrollView类似,但支持在新旧版本的Android上作为嵌套滚动的父视图和子视图。默认情况下启用嵌套滚动。
**ScrollView**

一个视图层次结构的布局容器,用户可以通过滚动来浏览它,使其比物理显示器更大。ScrollView是一个FrameLayout,这意味着您应该在其中放置一个包含整个可滚动内容的子项;此子项本身可以是具有复杂对象层次结构的布局管理器。
这将帮助您确定正在关注哪个布局。

已经使用了NestedScrollView但没有帮助... @ Dipali shah - Puspak Ghosh
在问题中,您提到您的Recyclerview位于ScrollView内部。 - Dipali Shah

0

您可以使用以下结构来实现嵌套滚动

<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 - Puspak Ghosh

0

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

android:layoutDirection="rtl"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接