NestedScrollView 嵌套Recyclerview 导致recyclerview无法滚动

NestedScrollView 嵌套Recyclerview 导致recyclerview无法滚动

这边不是处理两者的滚动冲突

<android.support.v4.widget.NestedScrollView
        android:overScrollMode="never"
        android:id="@+id/scroll_view"
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/taskdetailbg"
        tools:context=".TaskDetailActivity">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/actions"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/dp_5"
                android:layout_marginBottom="@dimen/dp_15"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/lb_all_action" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v4.widget.NestedScrollView>

一下是recyclerview的ItemView 也是嵌套一层recycelrView

<LinearLayout 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="wrap_content"
    android:layout_margin="@dimen/dp_5"
    android:background="@drawable/task_bg"
    android:elevation="@dimen/dp_1"
    android:orientation="horizontal"
    android:translationZ="@dimen/dp_1">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_52"
            android:gravity="center_vertical">

            <com.sunfusheng.progress.CircleProgressView
                android:id="@+id/progress_circular"
                app:cpv_radius="@dimen/dp_15"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_10"
                android:progress="50"
                app:cpv_progressNormalColor="#F2F2F2"
                app:cpv_progressNormalSize="@dimen/dp_5"
                app:cpv_progressReachColor="@color/colorPrimary"
                app:cpv_progressReachSize="@dimen/dp_5"
                app:cpv_progressTextVisible="false"
                app:cpv_reachCapRound="true" />

            <TextView
                android:id="@+id/tv_taskname"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_5"
                android:layout_marginRight="@dimen/dp_5"
                android:layout_weight="1"
                android:text="@string/getBoxTime"
                android:textColor="@color/text_six9"
                android:textSize="@dimen/sp_15" />

            <LinearLayout
                android:id="@+id/ll_switch"
                android:layout_width="@dimen/dp_30"
                android:layout_height="@dimen/dp_30"
                android:gravity="center">

                <ImageView
                    android:background="@drawable/up_close"
                    android:id="@+id/iv_switch"
                    android:layout_width="@dimen/dp_12"
                    android:layout_height="@dimen/dp_7"
                    />
            </LinearLayout>

        </LinearLayout>

        <com.github.aakira.expandablelayout.ExpandableRelativeLayout
            android:id="@+id/expandableLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:ael_duration="200"
            app:ael_expanded="false"
            app:ael_interpolator="linear"
            app:ael_orientation="vertical">

            <com.hhrj.watertable.view.MaxHeightRecyclerView
                android:id="@+id/data"
                android:layout_width="match_parent"
                android:layout_marginLeft="@dimen/dp_40"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="true"
                android:overScrollMode="never"
                app:maxHeight="@dimen/dp_200" />
        </com.github.aakira.expandablelayout.ExpandableRelativeLayout>
    </LinearLayout>
</LinearLayout>

我遇到的问题是ItemView中的recyclerView无法滚动

自己试了在Item的RecyclerView中监听

 @Override
    public boolean startNestedScroll(int axes) {
        LogUtil.d("开始滚动事件");
        return super.startNestedScroll(axes);
    }

    @Override
    public void onScrollStateChanged(int state) {
        LogUtil.d("滚动事件");
        super.onScrollStateChanged(state);
    }

发现根本没有进入滚动监听

在自定义的RecyclerView中添加

@Override
    public boolean onTouchEvent(MotionEvent e) {
        LogUtil.d("MaxHeightRecyclerView touched" + e.getAction());
        return super.onTouchEvent(e);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        LogUtil.d("MaxHeightRecyclerView onInterceptTouchEvent");
      //  requestDisallowInterceptTouchEvent(true);
        return super.onInterceptTouchEvent(e);
    }

发现以上两个事件都会进入

后来发现 // requestDisallowInterceptTouchEvent(true);

该方法是不允许父View拦截事件

我的需求还有是RecyclerView高度自适应 高度超过一定高度滑动

完整代码:

public class MaxHeightRecyclerView extends RecyclerView {
    private int mMaxHeight;

    public MaxHeightRecyclerView(Context context) {
        super(context);
    }

    public MaxHeightRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public MaxHeightRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, AttributeSet attrs) {
        TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightRecyclerView);
        mMaxHeight = arr.getLayoutDimension(R.styleable.MaxHeightRecyclerView_maxHeight, mMaxHeight);
        arr.recycle();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mMaxHeight > 0) {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxHeight, MeasureSpec.AT_MOST);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private Callback callback;

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public interface Callback {
        void moveEvent();
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        LogUtil.d("MaxHeightRecyclerView touched" + e.getAction());
        return super.onTouchEvent(e);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        LogUtil.d("MaxHeightRecyclerView onInterceptTouchEvent");
        requestDisallowInterceptTouchEvent(true);
        return super.onInterceptTouchEvent(e);
    }

    @Override
    public boolean startNestedScroll(int axes) {
        LogUtil.d("开始滚动事件");
        return super.startNestedScroll(axes);
    }

    @Override
    public void onScrollStateChanged(int state) {
        LogUtil.d("滚动事件");
        super.onScrollStateChanged(state);
    }
}

结束 还是事件分发问题,记录分享

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值