问题重现:
用到的第三方:
"pulltorefresh": "com.jwenfeng.pulltorefresh:library:1.2.7"
"banner" : "com.youth.banner:banner:1.4.10"
"recyclerview" : "com.android.support:recyclerview-v7:28.0.0"
"cardview" : "com.android.support:cardview-v7:22.1.0"
想象中是实现上面是轮播图下面显示卡片效果的UI,可以跟着一起滑动,刷新数据或加载数据,开开心心运行之后发现,有滑动效果但是内容只能显示出一屏????而我的数据可不止一屏,我开始怀疑是不是banner的问题,然而我发现随便放个控件也不行
我尝试去解决它:
从网上各种搜,
1.我在网上又仔细看了PullToRefreshLayout的介绍说只能有一个子内容,然后我在轮播图和集合外面套一层布局(又换成其他布局),失败
2.在代码中给RecyclerView设置网格布局管理器SpanCount给"1",失败
3.新建一个类继承RecyclerView并重写高度,失败
4.甚至我把Banner去掉,在代码中动态添加也失败了
5.从网上看到可能跟Adapter的加载方式有关系inflater.inflate(),失败
当然问题总会解决的:
design包里面有个NestedScrollView(ScrollView的升级版),还是如第一条那样,把最外层布局换为NestedScrollView得以解决,
如果NestedScrollView无法充满布局可以给android:fillViewport="true"这条属性的意思是允许它充满布局
最后看一下修改后的代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <com.jwenfeng.library.pulltorefresh.PullToRefreshLayout android:id="@+id/pull_refresh" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.youth.banner.Banner android:layout_width="match_parent" android:layout_height="150dp" android:id="@+id/banner" /> <android.support.v7.widget.RecyclerView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="150dp"> </android.support.v7.widget.RecyclerView> </RelativeLayout> </android.support.v4.widget.NestedScrollView> </com.jwenfeng.library.pulltorefresh.PullToRefreshLayout> </LinearLayout>