ToDou / nestrefresh

Android refresh kit by nest scroll. Pull-to-refresh and pull-to-load-more by behaviors

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RefreshBarLayout too Long , causing sliding and shaking

ThePrisonerNo25 opened this issue · comments

RefreshBarLayout too Long , causing sliding and shaking.
When you quickly pull up the RefreshBarLayout, immediately pull down the RecyclerView

example for your demo For example, in your demo SingleActivity(I added a ImageView):

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f4f4f5">

<com.todou.nestrefresh.RefreshBarLayout
    android:id="@+id/pull_refresh_hover"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <com.todou.nestrefresh.RefreshHeaderView
        android:id="@+id/view_refresh_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_normal"
        app:nr_layout_scrollFlags="flag_refresh_header"/>

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_margin="10dp"
        android:elevation="@dimen/common_elevation"
        android:background="@drawable/shape_radius"
        android:orientation="vertical"
        android:visibility="visible">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/text_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/margin_normal"
                android:layout_marginTop="@dimen/margin_normal"
                android:text="By ToDou"
                android:textStyle="bold"
                android:textSize="20sp"
                android:textColor="?android:attr/textColorSecondary"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="This is one nest refresh kit"
                android:layout_marginTop="6dp"
                android:layout_marginBottom="@dimen/margin_normal"
                app:layout_constraintTop_toBottomOf="@+id/text_title"
                app:layout_constraintLeft_toLeftOf="@+id/text_title"
                app:layout_constraintBottom_toBottomOf="parent"
                android:textSize="12sp"/>

        </android.support.constraint.ConstraintLayout>

        <View
            android:layout_width="240dp"
            android:layout_height="1dp"
            android:layout_marginLeft="@dimen/margin_normal"
            android:background="@drawable/shape_divider_header_title"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_inner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:layout_margin="0dp"
            android:visibility="visible"/>

    </LinearLayout>
    <ImageView
        android:id="@+id/iv_icon"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        android:src="@mipmap/ic_launcher_round"
        android:visibility="visible"
        />
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:layout_marginRight="@dimen/margin_normal"
        android:layout_marginLeft="@dimen/margin_normal"
        android:overScrollMode="never"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="140dp">

            <TextView
                android:layout_width="140dp"
                android:layout_height="match_parent"
                android:text="#1"
                style="@style/HorizontalItemStyle"/>

            <TextView
                android:layout_width="140dp"
                android:layout_height="match_parent"
                android:text="#2"
                style="@style/HorizontalItemStyle"/>

            <TextView
                android:layout_width="140dp"
                android:layout_height="match_parent"
                android:text="#3"
                style="@style/HorizontalItemStyle"/>

            <TextView
                android:layout_width="140dp"
                android:layout_height="match_parent"
                android:text="#4"
                style="@style/HorizontalItemStyle"/>

            <TextView
                android:layout_width="140dp"
                android:layout_height="match_parent"
                android:text="#5"
                style="@style/HorizontalItemStyle"
                android:layout_marginRight="0dp"/>

        </LinearLayout>
    </HorizontalScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/margin_normal"
        android:layout_marginLeft="@dimen/margin_normal"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        app:nr_layout_scrollFlags="flag_sticky">

        <TextView
            android:id="@+id/text_tab_one"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="Tab1"
            style="@style/TabStyle"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="Tab2"
            style="@style/TabStyle"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="Tab3"
            style="@style/TabStyle"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="Tab4"
            style="@style/TabStyle"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="Tab5"
            style="@style/TabStyle"/>
    </LinearLayout>

</com.todou.nestrefresh.RefreshBarLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/nest_refresh_bar_scroll_behavior"/>

</android.support.design.widget.CoordinatorLayout>

----------------------------------solution ----------------------------------
RefreshHeaderBehavior.class
override fun onNestedScrollAccepted(
coordinatorLayout: CoordinatorLayout,
child: V,
directTargetChild: View,
target: View,
axes: Int,
type: Int
) {
super.onNestedScrollAccepted(coordinatorLayout, child, directTargetChild, target, axes, type)
totalSpringOffset = calculateScrollUnconsumed().toFloat()
//this my solution
if (this.flingRunnable != null) {
child?.removeCallbacks(this.flingRunnable)
this.flingRunnable = null
}
}