PullToRefreshLayout中有两个内容控件时会造成只显示一屏的问题

问题重现:

用到的第三方:

"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>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值