Android 包装内容中的多个SwipeRefreshLayout和RecyclerView
我有一个布局有2个Android 包装内容中的多个SwipeRefreshLayout和RecyclerView,android,android-recyclerview,swiperefreshlayout,linearlayoutmanager,Android,Android Recyclerview,Swiperefreshlayout,Linearlayoutmanager,我有一个布局有2个SwipeRefreshLayout和RecyclerView,只有当layout\u高度固定时(例如:200dp),它才能工作。如果设置为wrap\u content,则项目不可见 我尝试了很多解决方案,但仍然不起作用。 我的布局: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
SwipeRefreshLayout
和RecyclerView
,只有当layout\u高度固定时(例如:200dp),它才能工作。如果设置为wrap\u content
,则项目不可见
我尝试了很多解决方案,但仍然不起作用。
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="UselessParent">
<TextView
android:id="@+id/feedNews1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text=""
android:textColor="#FFFFFF"
android:textSize="@dimen/text_feed_rss_title_size" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/feedNews2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text=""
android:textColor="#FFFFFF"
android:textSize="@dimen/text_feed_rss_title_size" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/adsContainerNews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
</LinearLayout>
</LinearLayout>
</ScrollView>
我的代码:
recyclerView1.setHasFixedSize(true);
recyclerView1.setNestedScrollingEnabled(false);
recyclerView2.setHasFixedSize(true);
recyclerView2.setNestedScrollingEnabled(false);
我也尝试过使用MyLinearLayoutManager
public class MyLinearLayoutManager extends android.support.v7.widget.LinearLayoutManager
但它不起作用
有解决办法吗
非常感谢简而言之,您应该删除
setHasFixedSize(true)
行
说明:
setHasFixedSize
如果您不希望回收视图的大小(宽度或高度)发生变化,则应将其设置为true。但是,在您的情况下,您希望它具有wrap\u内容
高度。所以你需要删除这条线
发生的情况如下:
- recyclerview最初没有项目,它的高度为0
- 接下来,添加项目。但是,它已设置为固定大小,因此不再调整大小
- 所以我们看不到新的行
这也是在将高度设置为某个值时看到项目的原因。使用NestedScrollView而不是scrollview是否有助于解决问题?@Joe S not Workkay。列表已填充还是为空?@Joe S已填充,因为如果我使用固定高度更改换行内容,则项目将被删除showed@Joe我不明白这个问题。问题在于包装内容中没有显示recycleview。使用single SwipeRefreshLayout和RecyclerView显示项目(高度为match_parent),但两者均未显示(高度=包裹内容),仅显示固定高度我已删除行setHasFixedSize(true),但项目未显示
public class MyLinearLayoutManager extends android.support.v7.widget.LinearLayoutManager