首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >垂直ScrollView内的水平ScrollView

垂直ScrollView内的水平ScrollView
EN

Stack Overflow用户
提问于 2015-09-04 09:03:35
回答 2查看 7.1K关注 0票数 6

所以我在垂直ScrollView里面有一个水平的ScrollView。我的布局中的所有东西都显示得很好,所有的卷轴都在我想要的方向上滚动,而且它做得很顺利。

我唯一的问题是,RecyclerView在ScrollView中的其他内容下面,当RecyclerView部分可见时,它将在RecyclerView底部与启动时的屏幕底部连线。这意味着RecyclerView上方的内容将从屏幕上推开。

有人知道为什么会发生这种事吗?我怎么才能解决呢?

下面是我刚才描述的一个简单的布局。您甚至不需要填充RecyclerView,它仍然会这样做。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:background="#fff"/>

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="#000"/>

    </LinearLayout>

</ScrollView>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-07 12:28:30

原来这个问题是向谷歌这里报告的,第81854期

据谷歌( Google )称,它正在按预期运作。问题在于RecyclerView将focusableInTouchMode设置为true。为了解决这个问题,我将focusableInTouchModefocusable设置为ScrollView的最顶层视图中的true。

下面是我在原始问题中提供的代码示例的修复:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:background="#fff"
            android:focusableInTouchMode="true"
            android:focusable="true"/>

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="#000"/>

    </LinearLayout>

</ScrollView>
票数 7
EN

Stack Overflow用户

发布于 2022-03-30 12:21:52

很长时间以来,我一直在寻找解决方案。最后,我偶然做出了决定。在您的活动中,找到ScrollView并为其添加一个触摸监听器。一切都会正常运转的

代码语言:javascript
复制
ScrollView scroll = findViewById(R.id.scroll);
        scroll.setOnTouchListener((view, motionEvent) -> {
            return false;
        });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32394115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档