垂直ScrollView

时间:2015-09-04 09:03:36

标签: android scrollview android-recyclerview

所以我在垂直ScrollView中有一个水平的RecyclerView。布局中的所有内容都显示得很好,并且都按照我想要的方向滚动,并且顺利完成。

我唯一的问题是,RecyclerView低于ScrollView中的其他内容,当RecyclerView部分可见时,它会在启动时将RecyclerView的底部与屏幕底部对齐。这意味着RecyclerView上方的内容将被推离屏幕。

有谁知道为什么会这样,以及我如何解决它?

这是一个简单的布局,可以完成我刚才描述的内容。你甚至不需要填充RecyclerView,它仍然会这样做。

<?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>

1 个答案:

答案 0 :(得分:6)

原来这个问题是在Google Issue - 81854

报告的

根据Google的说法,它正在按计划运作。问题在于RecyclerView将focusableInTouchMode设置为true。要解决此问题,我在ScrollView的最顶层视图中将focusableInTouchModefocusable设置为true。

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

<?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>
相关问题