垂直ScrollView内的水平RecyclerView

Dan*_*lio 5 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>
Run Code Online (Sandbox Code Playgroud)

Dan*_*lio 7

原来这个问题是谷歌在这里报告的问题 - 81854

根据Google的说法,它正在按计划运作.问题在于RecyclerView focusableInTouchMode设置为true.要解决我设置的问题,focusableInTouchModefocusable在ScrollView的最顶层视图中设置为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>
Run Code Online (Sandbox Code Playgroud)