kfrozen / HeaderCollapsibleLayout

A wrapper layout that can easily split your current layout into header and body, and provides smooth header collapsing action with related event callbacks.
Apache License 2.0
24 stars 3 forks source link

RecyclerView 如果添加刷新和加载,怎么解决滑动冲突的问题 #4

Open jackandroid2016 opened 6 years ago

jackandroid2016 commented 6 years ago

RecyclerView 如果添加刷新和加载,会出现推上去之后拉不下来的情况

kfrozen commented 6 years ago

@jackandroid2016 您好,方便把相关的layout xml代码发上来看看吗?

jackandroid2016 commented 6 years ago

这是HeaderCollapsibleLayout

<?xml version="1.0" encoding="utf-8"?> <FrameLayout 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:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".function.baby.activity.BabyDetailActivity">

<com.troy.collapsibleheaderlayout.HeaderCollapsibleLayout
    android:id="@+id/default_header_collapsible_layout_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:bottomPanelLayoutId="@layout/comp_collapsible_layout_body"
    app:overshootDistance="3000"
    app:topPanelLayoutId="@layout/comp_collapsible_layout_header" />
<!--app:supportAutoExpand="false" />-->

<include layout="@layout/common_toolbar" />

jackandroid2016 commented 6 years ago

这个是comp_collapsible_layout_body.xml

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">

<com.scwang.smartrefresh.layout.SmartRefreshLayout
    android:id="@+id/srl_baby_log"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</com.scwang.smartrefresh.layout.SmartRefreshLayout>

jackandroid2016 commented 6 years ago

这个是comp_collapsible_layout_header.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/default_header_placeholder_id" android:layout_width="match_parent" android:layout_height="250dp" android:background="@mipmap/my_bg">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/dp_60"
    android:layout_marginLeft="@dimen/dp_15"
    android:layout_marginRight="@dimen/dp_15">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/civ_baby_head"
        android:layout_width="@dimen/dp_60"
        android:layout_height="@dimen/dp_60"
        android:src="@mipmap/default_head_icon" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/civ_baby_head"
        android:layout_marginLeft="@dimen/dp_15"
        android:layout_gravity="center_vertical"
        android:text="彭于晏"
        android:textStyle="bold"
        android:textSize="@dimen/sp_14"
        android:textColor="@color/white"
        android:padding="@dimen/dp_5"
        android:shadowColor="#ff000000"
        android:shadowRadius="1"
        android:shadowDx="5"
        android:shadowDy="5" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_40"
    android:layout_above="@id/bottom_line">

    <TextView
        android:id="@+id/tv_tab_log"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="日志"
        android:textStyle="bold"
        android:textSize="@dimen/sp_14"
        android:textColor="@color/white"
        android:padding="@dimen/dp_5"
        android:shadowColor="#ff000000"
        android:shadowRadius="1"
        android:shadowDx="5"
        android:shadowDy="5" />

    <TextView
        android:id="@+id/tv_tab_live"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="直播"
        android:textStyle="bold"
        android:textSize="@dimen/sp_14"
        android:textColor="@color/white"
        android:padding="@dimen/dp_5"
        android:shadowColor="#ff000000"
        android:shadowRadius="1"
        android:shadowDx="5"
        android:shadowDy="5" />

    <TextView
        android:id="@+id/tv_tab_record"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="成长记录"
        android:textStyle="bold"
        android:textSize="@dimen/sp_14"
        android:textColor="@color/white"
        android:padding="@dimen/dp_5"
        android:shadowColor="#ff000000"
        android:shadowRadius="1"
        android:shadowDx="5"
        android:shadowDy="5" />

</LinearLayout>

<include layout="@layout/invitation_code"
    android:id="@+id/bottom_line"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>

kfrozen commented 6 years ago

@jackandroid2016 我在本机上试验了你说的情况,我这边用的官方的SwipeRefreshLayout,是可以正常工作的,下面是我body layout的代码: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_refresh" android:layout_width="match_parent" android:layout_height="match_parent">

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

</android.support.v4.widget.SwipeRefreshLayout>

您那边不work的话,首先建议看下SmartRefreshLayout中有没有对于scroll事件进行拦截,其次如果业务允许,可以考虑将swipe refresh移到HeaderCollapsibleLayout的外层,这样滚动上体验会更好一些。