LOGCAT.IO | CoordinatorLayout和列表嵌套冲突的问题

为什么用ListView呢,因为数据是通过socket给过来的,而且每次都是一整组数据,用recycleView会每个格子刷一遍,数据改变就刷。但是ListView替换数据之后notifydatachanged就可以了,adapter只会刷新一次。

首先自定义ListView,不给他来回滑动

package com.fota.android.moudles.quotation;

import android.content.Context;
import android.os.Build;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.util.AttributeSet;
import android.widget.ListView;

public class NoScrollListView extends ListView implements NestedScrollingChild {

        private final NestedScrollingChildHelper mScrollingChildHelper;

        public NoScrollListView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mScrollingChildHelper = new NestedScrollingChildHelper(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                setNestedScrollingEnabled(true);
            }


        }


        @Override
        public void setNestedScrollingEnabled(boolean enabled) {
            mScrollingChildHelper.setNestedScrollingEnabled(enabled);
        }

        @Override
        public boolean isNestedScrollingEnabled() {
            return mScrollingChildHelper.isNestedScrollingEnabled();
        }

        @Override
        public boolean startNestedScroll(int axes) {
            return mScrollingChildHelper.startNestedScroll(axes);
        }

        @Override
        public void stopNestedScroll() {
            mScrollingChildHelper.stopNestedScroll();
        }

        @Override
        public boolean hasNestedScrollingParent() {
            return mScrollingChildHelper.hasNestedScrollingParent();
        }

        @Override
        public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,
                                            int dyUnconsumed, int[] offsetInWindow) {
            return mScrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed,
                    dxUnconsumed, dyUnconsumed, offsetInWindow);
        }

        @Override
        public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
            return mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
        }

        @Override
        public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
            return mScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
        }

        @Override
        public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
            return mScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY);
        }

    }

然后在使用时,在外层嵌套NestedScrollView

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <com.xxx.widget.NoScrollListView
        android:id="@+id/quotation_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/order_bg"
        android:divider="#FAFAFA"
        android:dividerHeight="0.5dp"
        android:footerDividersEnabled="true"
        android:scrollbars="none" />

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

即可