【发布时间】:2018-08-27 15:18:10
【问题描述】:
我有一个包含 2 个 SwipeRefreshLayout 和 RecyclerView 的布局,它仅在 layout_height 固定时才有效(例如:200dp)。如果设置为wrap_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>
在这种情况下,只显示第一个RecyclerView
我的构建:
compileSdkVersion 27
minSdkVersion 14
targetSdkVersion 27
implementation 'com.android.support:recyclerview-v7:27.1.1'
我的代码:
recyclerView1.setHasFixedSize(true);
recyclerView1.setNestedScrollingEnabled(false);
recyclerView2.setHasFixedSize(true);
recyclerView2.setNestedScrollingEnabled(false);
我也试过MyLinearLayoutManager
public class MyLinearLayoutManager extends android.support.v7.widget.LinearLayoutManager
但它不起作用。
有解决办法吗?
非常感谢
【问题讨论】:
-
使用 NestedScrollView 代替 scrollview 是否有助于解决您的问题?
-
@Joe S 不工作
-
好的。列表是满的还是空的?
-
@Joe S 已填充,因为如果我将 wrap_content 更改为固定高度,则会显示项目
-
@Joe S 我不明白这个问题。问题在于 wrap_content 中没有显示回收视图。使用单个 SwipeRefreshLayout 和 RecyclerView 显示项目(高度为 match_parent),但两者均不显示(height=wrap_content),仅显示固定高度
标签: android android-recyclerview swiperefreshlayout linearlayoutmanager