[英]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.