我在一个片段中有 2 个 RecyclerViews。但只显示第一个

I have 2 RecyclerViews in a Fragment. But only the 1st one is shown

我正在尝试在片段中包含两个 RecyclerView。其中一个是水平对齐的 RecyclerView,另一个是垂直对齐的。但是只有水平的 RecyclerView 是可见的。 (如果我在布局文件中更改 RecyclerView 的顺序,垂直的 RecyclerView 是可见的,所以我很确定 RecyclerView 没有任何问题。)

根据类似问题的其他答案,我在两个 RecyclerView 中都添加了 layout_weight=1。但是第二个RecyclerView还是没有显示。

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/CategoryPageRecyclerView"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="0dp"
                android:scrollbars="none" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/ItemsRecyclerView"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="0dp"
                android:scrollbars="vertical" />

        </android.support.v4.widget.SwipeRefreshLayout>
    </LinearLayout>

我感觉 SwipeRefreshLayout 引起了问题。关于如何解决此问题的任何想法?

SwipeRefreshView 仅支持一个直接子代 - 将 RecyclerViews 包裹在 LinearLayout 中,它将起作用。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/CategoryPageRecyclerView"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="0dp"
                android:scrollbars="none" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/ItemsRecyclerView"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="0dp"
                android:scrollbars="vertical" />

        </LinearLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

希望对你有帮助,有问题可以评论