java - 我在一个 fragment 中有 2 个 RecyclerViews。但只显示第一个

标签 java android android-fragments android-recyclerview swiperefreshlayout

我想在一个 fragment 中有两个 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 仅支持一个直接 subview - 将 RecyclerView 包装在 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>

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

关于java - 我在一个 fragment 中有 2 个 RecyclerViews。但只显示第一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44466166/

相关文章:

java - :ValueChangeListener nullifying EJB injection

android - fragment 仅在应用程序设计为在手机和平​​板电脑上运行时才有用吗?

android - 如何在 FragmentStatePagerAdapter 的 fragment 中动态设置 TextView 的文本

java - Android-Helloworld应用/不清楚

java - Java 中的通用字段多态性

java - 向对话框添加多项选择并使其正常运行

java - 在 Applet 中嵌入 JFrame

Android WorkManager 并发作业计数/最大值

android - 使用自定义图像在 Google Android 模拟器中运行 Xposed

android - 如何排除 Kotlin 中测试类的显式Api 警告?