简体   繁体   English

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

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

I'm trying to have two RecyclerViews in a Fragment. 我试图在片段中有两个RecyclerViews。 One of them being a horizontally aligned RecyclerView, and the other a vertically aligned one. 其中一个是水平对齐的RecyclerView,另一个是垂直对齐的。 But only the horizontal RecyclerView is visible. 但只有水平的RecyclerView可见。 (The vertical RecyclerView is visible if I change the order of the RecyclerViews in the layout file, so I'm pretty sure there's nothing wrong with the RecyclerViews.) (如果我在布局文件中更改RecyclerViews的顺序,则可以看到垂直的RecyclerView,所以我很确定RecyclerViews没有任何问题。)

As per other answers to similar questions, I've added the layout_weight=1 in both the RecyclerViews. 根据类似问题的其他答案,我在RecyclerViews中添加了layout_weight=1 But the 2nd RecyclerView still doesn't show. 但第二台RecyclerView仍然没有显示。

Here's my layout file: 这是我的布局文件:

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

I have a feeling the SwipeRefreshLayout is causing an issue. 我有一种感觉SwipeRefreshLayout导致问题。 Any ideas on how to fix this? 有想法该怎么解决这个吗?

SwipeRefreshView supports only one direct child - wrap RecyclerView s in LinearLayout and it will work. SwipeRefreshView只支持一个直接子包 - 在LinearLayout包装RecyclerView ,它将起作用。

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

Hope this helps you, comment if you have any questions 希望这对你有所帮助,如果你有任何问题请评论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅在第一个片段上隐藏浮动操作按钮? - how to hide the float action button only on the 1st fragment? 我有一个 Jtable,其中一列中有一个按钮,我想在按下按钮时访问第一列中的值 - I have a Jtable with a button in one of the columns and I want to access the value in the 1st column when I press the button 使用 JPanel 显示不同的信息,但只能显示第一次 - Using a JPanel to display different info, but it can only be shown the 1st time 我不明白代码片段的输出。 能给我一个飞机吗? - I can't understand the output of the code fragment. can some one explane it to me please? 如何在 2 个 recyclerviews 中只选择一个复选框 - How to select only one checkbox within 2 recyclerviews 如何在类和片段之间进行通信。 我创建了一个类,我希望它执行网络请求并返回一个数组列表 - how to communicate between class and a fragment. i have created a class that i want it perform network request an return an arraylist Android-DialogFragment从片段显示。 取消DialogFragment时如何显示Fragment中的Toast? - Android - DialogFragment is shown from a Fragment. How to show Toast from Fragment when DialogFragment is dismissed? 膨胀 class 片段时出错。 我可以在这里做什么? - Error inflating class fragment. What can I do here? 将多个JTables作为一项作业打印-Book对象仅打印第一个表 - Printing multiple JTables as one job — Book object only prints 1st table ModelAttribute仅将第一个值添加到列表中 - ModelAttribute adds only 1st value into List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM