lcodecorex / TwinklingRefreshLayout

RefreshLayout that support for OverScroll and better than iOS. 支持下拉刷新和上拉加载的RefreshLayout,自带越界回弹效果,支持RecyclerView,AbsListView,ScrollView,WebView
Apache License 2.0
3.99k stars 671 forks source link

TwinklingRefreshLayout嵌套NestedScrollView的,里面还有recycleView, #182

Open liguangze opened 5 years ago

liguangze commented 5 years ago

滑动不顺畅怎么解决呢,去掉TwinklingRefreshLayout, mRcyGroupSall.setNestedScrollingEnabled(false);,这个可以解决,但是没有了刷新了,怎么才能全部兼容到了呢

chenli3238 commented 5 years ago

滑动不顺畅怎么解决呢,去掉TwinklingRefreshLayout, mRcyGroupSall.setNestedScrollingEnabled(false);,这个可以解决,但是没有了刷新了,怎么才能全部兼容到了呢

解决了没有?我也碰到这问题了

liguangze commented 5 years ago

@chenli3238 还没有,目前就是不顺畅着

chenli3238 commented 5 years ago

@liguangze 我卡了三天了,各种监听事件,改源码都不行

liguangze commented 5 years ago

@chenli3238 一样,怎么解决好啊

chenli3238 commented 5 years ago

@liguangze 没解决,先放着吧,除非不嵌套NestedScrollView或者ScrollView

The-WindRises commented 5 years ago

将TwinklingRefreshLayout放在最外层,然后内部放一个MyScrollview 其他所有布局内容放在MyScrollview中 MyScrollview 代码如下

public class MyScrollview extends NestedScrollView {

Context context;
private int downX;
private int downY;
private int mTouchSlop;

public MyScrollview(Context context) {
    super(context);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

public MyScrollview(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    int action = e.getAction();
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            downX = (int) e.getRawX();
            downY = (int) e.getRawY();
            break;
        case MotionEvent.ACTION_MOVE:
            int moveY = (int) e.getRawY();
            if (Math.abs(moveY - downY) > mTouchSlop) {
                return true;
            }
    }
    return super.onInterceptTouchEvent(e);
}

}

liguangze commented 5 years ago

@1218362859 感谢,的确是可以,

recycleView也需要自己定义 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int expandSpec = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);
}
The-WindRises commented 5 years ago

@liguangze 我8.0有问题 还在解决 你刚写的这个是什么意思?

The-WindRises commented 5 years ago

已修改,将继承ScrollView改成继承NestedScrollView

danny70339 commented 5 years ago

@liguangze 我也是TwinklingRefreshLayout嵌套NestedScrollView,NestedScrollView在嵌套RecycleView

mNestedScrollView.setNestedScrollingEnabled(false); mRecycleView.setNestedScrollingEnabled(false); 我這樣設置後就能流暢滑動也能刷新或加載 但是卻會越加載越不流暢,之後就閃退了 請問有遇到相同的狀況嗎

The-WindRises commented 5 years ago

@liguangze 我也是TwinklingRefreshLayout嵌套NestedScrollView,NestedScrollView在嵌套RecycleView

mNestedScrollView.setNestedScrollingEnabled(false); mRecycleView.setNestedScrollingEnabled(false); 这样我设置后就能流畅滑动也。能刷新或加载 但是却会越加载越不流畅,就之后闪退了 请问有遇到相同的状况吗

是你返回的json解析的太慢了吧,后台只返回有用的字段,还有可能你加载的图片后台上传过大

liguangze commented 5 years ago

@danny70339 闪退报啥错

danny70339 commented 5 years ago

@1218362859 應該不是解析太慢的問題,我試著把佈局改成TwinklingRefreshLayout只嵌套RecycleView跟使用同一隻API來加載,就變得非常順暢也不會閃退

The-WindRises commented 5 years ago

@danny70339 把整个布局文件代码发出来看下

danny70339 commented 5 years ago

@liguangze 老實說我看log看不太出來是什麼問題,下面是我的log

10-31 10:19:17.563 24528-24528/? E/Zygote: v2 10-31 10:19:17.563 24528-24528/? E/Zygote: accessInfo : 0 10-31 10:19:18.123 24528-24542/? E/GMPM: getGoogleAppId failed with status: 10 10-31 10:19:18.133 24528-24542/? E/GMPM: Uploading is not possible. App measurement disabled 10-31 10:19:18.323 24547-24547/? E/Zygote: v2 10-31 10:19:18.323 24547-24547/? E/Zygote: accessInfo : 0 10-31 10:19:18.343 24528-24528/? E/SamsungNotes$SC$Utils: NoSuchMethodException : java.lang.NoSuchMethodException: getEnableStatus [class java.lang.String, class java.lang.Boolean] 10-31 10:19:18.343 24558-24558/? E/Zygote: v2 10-31 10:19:18.343 24558-24558/? E/Zygote: accessInfo : 0 10-31 10:19:18.743 24547-24583/? E/ServiceManager: [#CMH#] Failed binding To Service EnhanceService 10-31 10:19:18.763 24594-24594/? E/Zygote: v2 10-31 10:19:18.763 24594-24594/? E/Zygote: accessInfo : 0 10-31 10:19:18.953 715-1075/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=386, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ] 10-31 10:19:19.813 715-1187/? E/GameManagerService: remoteCallback died, callback: com.samsung.android.game.IGameManagerCallback$Stub$Proxy@96e169c, cookie: null 10-31 10:19:20.453 323-930/? E/NetlinkEvent: NetlinkEvent::decode(): buffer'change@/devices/battery/power_supply/battery' size:713,format:0 10-31 10:19:20.453 216-290/? E/NetlinkEvent: NetlinkEvent::decode(): buffer'change@/devices/battery/power_supply/battery' size:713,format:0 10-31 10:19:20.533 715-1046/? E/InputDispatcher: channel ~ Channel is unrecoverably broken and will be disposed! 10-31 10:19:20.763 24614-24614/? E/Zygote: v2 10-31 10:19:20.763 24614-24614/? E/Zygote: accessInfo : 0 10-31 10:19:21.113 24630-24630/? E/Zygote: v2 10-31 10:19:21.123 24630-24630/? E/Zygote: accessInfo : 0 10-31 10:19:21.343 24614-24614/? E/CII: CommonIMSInterface: VoLTE CSC feature disabled. 10-31 10:19:21.363 24614-24614/? E/CII: CommonIMSInterface: VoLTE CSC feature disabled. 10-31 10:19:21.393 1111-15661/? E/PhoneInterfaceManager: [PhoneIntfMgr] getDataEnabled: no phone subId=-1 retVal=false 10-31 10:19:21.723 24630-24645/? E/ContactsProvider_EventLog: Flush buffer to file cnt : 1 size : 0Kb duration : 92ms lastUpdatedAfter : 1540952361736 ms mFlush_time_threasold : 2000 mCurrentSize : 129 10-31 10:19:25.413 230-230/? E/lowmemorykiller: Error writing /proc/21983/oom_score_adj; errno=22 10-31 10:19:25.483 22234-22278/? E/BtGatt.GattService: [GSIM LOG]: gsimLogHandler: com.android.bluetooth, msg: MESSAGE_STOP_SCAN 10-31 10:19:25.613 715-1187/? E/WifiService: Multicaster binderDied 10-31 10:19:25.703 22234-22248/? E/bt_btif: btif_vhci_sock_cleanup 10-31 10:19:26.013 22234-22253/? E/BluetoothAdapterState: stateChangeCallback : 0 10-31 10:19:26.073 22234-22234/? E/BluetoothAdapterService: onProfileServiceStateChanged() serviceName=com.android.bluetooth.gatt.GattService, state=10, Message sending 10-31 10:19:26.073 22234-22234/? E/BtGatt.GattService: notifyProfileServiceStateChanged 10-31 10:19:26.073 22234-22234/? E/BluetoothAdapterService: handleMessage() - Message: 1 10-31 10:19:26.073 22234-22234/? E/BluetoothAdapterService: processProfileServiceStateChanged() serviceName=com.android.bluetooth.gatt.GattService, state=10, Before synchronized 10-31 10:19:26.333 715-1046/? E/InputDispatcher: channel ~ Channel is unrecoverably broken and will be disposed!

danny70339 commented 5 years ago

@1218362859 最外面包了一層FrameLayout,但是不知道為什麼顯示不出來

<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:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/normal_bg" android:orientation="vertical">

<com.melnykov.fab.FloatingActionButton
    android:id="@+id/fab_add_commodity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="30dp"
    android:clickable="true"
    android:paddingBottom="10dp"
    android:src="@mipmap/ic_carera"
    app:fabSize="normal"
    app:fab_colorNormal="@color/button_baker_miller_pink" />

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:background="@color/normal_bg"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/toolbar_color">

        <TextView
            android:id="@+id/seller_data_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/title_seller_detail"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="16sp" />
    </android.support.v7.widget.Toolbar>

    <com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/sv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="vertical">

                    <com.makeramen.roundedimageview.RoundedImageView
                        android:id="@+id/riv_seller_image"
                        android:layout_width="75dp"
                        android:layout_height="75dp"
                        android:layout_gravity="center"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="20dp"
                        android:layout_marginRight="8dp"
                        android:src="@drawable/image_load_fail"
                        app:layout_constraintHorizontal_bias="0.501"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:riv_oval="true" />

                    <TextView
                        android:id="@+id/tv_seller_name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:gravity="center"
                        android:textAlignment="center"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/riv_seller_image" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="20dp"
                        android:orientation="horizontal">

                        <LinearLayout
                            android:id="@+id/linearLayout3"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="5dp"
                            android:layout_weight="1"
                            android:gravity="end"
                            android:orientation="horizontal"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent">

                            <TextView
                                android:id="@+id/textView46"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="@string/user_review_amount"
                                android:textSize="16sp"
                                app:layout_constraintRight_toLeftOf="@+id/riv_seller_image"
                                app:layout_constraintTop_toBottomOf="@+id/tv_seller_name" />

                            <TextView
                                android:id="@+id/tv_review_amount"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="5dp"
                                android:textColor="@color/black"
                                android:textSize="18sp"
                                app:layout_constraintLeft_toRightOf="@+id/textView46"
                                app:layout_constraintTop_toBottomOf="@+id/tv_seller_name" />

                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/linearLayout2"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="5dp"
                            android:layout_weight="1"
                            android:gravity="start"
                            android:orientation="horizontal"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toEndOf="@+id/linearLayout3">

                            <TextView
                                android:id="@+id/textView47"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="@string/user_commodity_amount"
                                android:textSize="16sp"
                                app:layout_constraintTop_toBottomOf="@+id/tv_seller_name"
                                tools:layout_editor_absoluteX="249dp" />

                            <TextView
                                android:id="@+id/tv_commodity_amount"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textColor="@color/black"
                                android:textSize="18sp"
                                app:layout_constraintLeft_toRightOf="@+id/textView47"
                                app:layout_constraintTop_toBottomOf="@+id/tv_seller_name" />

                        </LinearLayout>

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="horizontal">

                    <RelativeLayout
                        android:id="@+id/rl_follow_state"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="1dp"
                        android:layout_weight="1"
                        android:background="@color/follow"
                        android:gravity="center">

                        <ImageView
                            android:id="@+id/iv_follow_state"
                            android:layout_width="10dp"
                            android:layout_height="10dp"
                            android:layout_centerVertical="true"
                            android:layout_marginEnd="5dp"
                            android:layout_toStartOf="@+id/tv_follow_state"
                            app:srcCompat="@drawable/plus" />

                        <TextView
                            android:id="@+id/tv_follow_state"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="5dp"
                            android:layout_marginTop="6dp"
                            android:layout_marginBottom="6dp"
                            android:text="@string/follow"
                            android:textColor="@color/white" />
                    </RelativeLayout>

                    <LinearLayout
                        android:id="@+id/rl_follow_amount"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="1dp"
                        android:layout_weight="1"
                        android:background="@color/setting_text_bg"
                        android:gravity="center">

                        <TextView
                            android:id="@+id/textView51"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="6dp"
                            android:layout_marginEnd="2dp"
                            android:layout_marginBottom="6dp"
                            android:layout_weight="1"
                            android:gravity="end"
                            android:text="@string/follow" />

                        <TextView
                            android:id="@+id/tv_follow_amount"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="2dp"
                            android:layout_weight="1"
                            android:gravity="start"
                            android:textColor="@color/black" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/rl_fans_amount"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@color/setting_text_bg"
                        android:gravity="center">

                        <TextView
                            android:id="@+id/textView52"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="6dp"
                            android:layout_marginEnd="2dp"
                            android:layout_marginBottom="6dp"
                            android:layout_weight="1"
                            android:gravity="end"
                            android:text="@string/fans" />

                        <TextView
                            android:id="@+id/tv_fans_amount"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="2dp"
                            android:layout_weight="1"
                            android:gravity="start"
                            android:textColor="@color/black" />
                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/ll_review"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/imageView3"
                        android:layout_width="wrap_content"
                        android:layout_height="20dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="20dp"
                        android:layout_marginTop="12dp"
                        android:layout_marginBottom="12dp"
                        android:src="@drawable/reviewgood" />

                    <TextView
                        android:id="@+id/tv_good_review_amount"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="center_vertical"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:textColor="@color/black"
                        android:textSize="16sp" />

                    <ImageView
                        android:id="@+id/imageView4"
                        android:layout_width="wrap_content"
                        android:layout_height="20dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="20dp"
                        android:src="@drawable/reviewnormal" />

                    <TextView
                        android:id="@+id/tv_normal_review_amount"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="center_vertical"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:textColor="@color/black"
                        android:textSize="16sp" />

                    <ImageView
                        android:id="@+id/imageView5"
                        android:layout_width="wrap_content"
                        android:layout_height="20dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="20dp"
                        android:src="@drawable/reviewbad" />

                    <TextView
                        android:id="@+id/tv_bad_review_amount"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="center_vertical"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:textColor="@color/black"
                        android:textSize="16sp" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/tv_info"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/black"
                        android:gravity="center"
                        android:paddingTop="5dp"
                        android:paddingBottom="5dp"
                        android:text="@string/personal_information"
                        android:textColor="@color/white"
                        android:textSize="16sp" />

                    <TextView
                        android:id="@+id/tv_seller_description"
                        android:layout_width="match_parent"
                        android:layout_height="95dp"
                        android:paddingLeft="20dp"
                        android:paddingTop="5dp"
                        android:paddingRight="20dp"
                        android:paddingBottom="5dp"
                        android:textSize="14sp" />
                </LinearLayout>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_commodity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/normal_bg"
                    android:overScrollMode="never">

                </android.support.v7.widget.RecyclerView>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
</LinearLayout>

The-WindRises commented 5 years ago

@danny70339 看我之前写的评论 然后把android.support.v4.widget.NestedScrollView 改成MyScrollview的路径 最后 把RecyclerView的android:layout_height改成match_parent

danny70339 commented 5 years ago

@1218362859 還是一樣的狀況,另外我發現了新的現象,當我滑到越下面的時候會越慢反之越上面越滑順,舉例來說加設我RecyclerView裡已經加載了150個item,當我往下滑越靠近第150個的時候會開始不滑順,反之當我往回滑越靠近第1個的時候就越滑順

danny70339 commented 5 years ago

@liguangze @1218362859 抱歉兩位我又試了一下發現,這好像是NestedScrollView嵌套RecyclerView的問題,TwinklingRefreshLayout是無辜的我誤會他了 感謝兩位的協助

The-WindRises commented 5 years ago

@danny70339 解决了?

danny70339 commented 5 years ago

@1218362859 還沒,但是知道確切的方向了,只是想說跟這個庫無關怕造成你們的困擾

danny70339 commented 5 years ago

@1218362859 @liguangze 這個是問題的原因: https://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working#52309179

liguangze commented 5 years ago

@1218362859 ok 感谢

danny70339 commented 5 years ago

@1218362859 @liguangze 已用RecyclerView加上HeaderView來解決這個問題了

18640243061 commented 1 year ago

就直接把tw放在ns外层就好了