繁体   English   中英

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

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

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

根据类似问题的其他答案,我在RecyclerViews中添加了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只支持一个直接子包 - 在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>

希望这对你有所帮助,如果你有任何问题请评论

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM