Android:SwipeRefreshLayout+RecyclerView+BaseQuickAdapter SwipeRefreshLayout无法拉出来

我的使用场景是这样的:

      布局文件:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray_f5">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>

      非常简单,这个就不分析了。

      使用上:我除了列表还在adapter中使用了addHeaderView,添加的是一个有可能会隐藏的控件,根据后台数据来的。当控件隐藏时,下拉刷新就失效了,无法下拉

      解决办法,在添加的headerView控件中,增加一个不明显不会隐藏的控件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        app:layout_constraintTop_toTopOf="parent"/>
    <TextView
        android:id="@+id/tv_notify"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:textSize="10sp"
        android:gravity="center"
        android:background="@color/blue_ff"
        android:textColor="@color/white"
        android:text="为您推荐x条内容"
        android:layout_marginTop="3dp"
        android:visibility="gone"
        app:layout_constraintTop_toBottomOf="@+id/view"/>
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="84dp"
        app:layout_constraintTop_toBottomOf="@+id/tv_notify"/>

</android.support.constraint.ConstraintLayout>

上面代码的recycerView就是会根据数据来显隐,假如不加那个2dp的View,在recyclerView和TextView都隐藏时,最外面的SwipeRefresh会无法拉出,

 

原因具体还没分析,我猜测一下啊,我这人比较喜欢猜测问题,然后再去验证猜想。触发下拉刷新条件,是RecyclerView拉到顶部,继续下拉。在BaseQuickAdapter 添加了header的情况下,必须滚动到header顶部才算滚动完成,才会触发下拉刷新控件,而我们将header里的控件全部隐藏后,对于adapter就永远拉不到顶。有空的话,再调试一下这个bug

 

至于我为什么不猜测是不是NestedScrolling嵌套滚动出错,因为上面界面是在ViewPager里的,而ViewPager我还用CoordinatorLayout包起来跟另一个控件做了联动效果,而这些嵌套滚动都是正常的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值