NestedScrollView嵌套RecyclerView只显示一行的问题

    xiaoxiao2021-04-18  66

    1、添加属性设置 //设置布局管理器 LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setSmoothScrollbarEnabled(true); linearLayoutManager.setAutoMeasureEnabled(true); mRecyclerView.setLayoutManager(linearLayoutManager); mRecyclerView.setHasFixedSize(true); mRecyclerView.setNestedScrollingEnabled(false); mRecyclerView.setAdapter(new RecommendGoodsAdapter(context,mBottoms));

    2、重写NestedScrollView

    package com.geridge.wjy.views; import android.content.Context; import android.support.v4.widget.NestedScrollView; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewConfiguration; /** * Created by zzq on 2017/3/17 0017. */ public class ScrollviewNestedRecyclerview extends NestedScrollView { private int downX; private int downY; private int mTouchSlop; public ScrollviewNestedRecyclerview(Context context) { super(context); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } public ScrollviewNestedRecyclerview(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } public ScrollviewNestedRecyclerview(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); } } 3、如果上面都加了还是不行

    添加android:fillViewport="true"属性

    <?xml version="1.0" encoding="utf-8"?> <com.geridge.wjy.views.ScrollviewNestedRecyclerview 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:scrollbars="none" android:fillViewport="true" android:overScrollMode="never"> 设置RecyclerView的layout_height属性为wrap_content

    设置RecyclerView的item_layout最外层的容器layout_height属性为wrap_content

    转载请注明原文地址: https://ju.6miu.com/read-675170.html

    最新回复(0)