NestedScrollView不会与Recyclerview里面

我有这样的布局:

<NestedScrollView> <RecyclerView> // vertical recycler view <RecyclerView/> // horizontal recycler view <RecyclerView/> <RecyclerView/> ... <RecyclerView> </NestedScrollView> 

结果看起来像Google Play商店: 在这里输入图像说明

我在horizontal Recycler视图中禁用了NestedScrolling:

 horizontalRecyclerView.setHasFixedSize(true); horizontalRecyclerView.setNestedScrollingEnabled(false); 

我的问题:

vertical recyclerview不滚动,每当ACTION_UP发生, vertical recyclerview也停止滚动。

我怎样才能嵌套vertical recyclerviewnestedscrollviewhorizontal recyclerviewvertical recyclerview像Playstore和保持滚动平稳。

解决了:

使用@vrund purohit的自定义嵌套滚动视图(下面的代码),并禁用nestedscroll纵向和横向recyclerview:

 verticalRecyclerView.setNestedScrollingEnabled(false); ... add each horizontal recyclerviews: horizontalRecyclerView.setNestedScrollingEnabled(false); 

Related of "NestedScrollView不会与Recyclerview里面"

我有这个相同的问题,我通过自定义NeatedScrollView解决了这个问题。

这是这个类。

MyNestedScrollView

 public class MyNestedScrollView extends NestedScrollView { @SuppressWarnings("unused") private int slop; @SuppressWarnings("unused") private float mInitialMotionX; @SuppressWarnings("unused") private float mInitialMotionY; public MyNestedScrollView(Context context) { super(context); init(context); } private void init(Context context) { ViewConfiguration config = ViewConfiguration.get(context); slop = config.getScaledEdgeSlop(); } public MyNestedScrollView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public MyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private float xDistance, yDistance, lastX, lastY; @SuppressWarnings("unused") @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: xDistance = yDistance = 0f; lastX = ev.getX(); lastY = ev.getY(); // This is very important line that fixes computeScroll(); break; case MotionEvent.ACTION_MOVE: final float curX = ev.getX(); final float curY = ev.getY(); xDistance += Math.abs(curX - lastX); yDistance += Math.abs(curY - lastY); lastX = curX; lastY = curY; if (xDistance > yDistance) { return false; } } return super.onInterceptTouchEvent(ev); } public interface OnScrollChangedListener { void onScrollChanged(NestedScrollView who, int l, int t, int oldl, int oldt); } private OnScrollChangedListener mOnScrollChangedListener; public void setOnScrollChangedListener(OnScrollChangedListener listener) { mOnScrollChangedListener = listener; } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mOnScrollChangedListener != null) { mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt); } } } 

快乐的编码。

使用下面的代码进行平滑滚动:

 ViewCompat.setNestedScrollingEnabled(recyclerView, false); 

[已解决]我有同样的问题与水平recycleview。 更改gradle回购为recycleview

编译'com.android.support:recyclerview-v7:23.2.1'写这个:linearLayoutManager.setAutoMeasureEnabled(true);

修正了与更新中的各种度量规格方法相关的错误

检查http://developer.android.com/intl/es/tools/support-library/features.html#v7-recyclerview

我在23.2.1库中发现问题:当item为match_parent时,回收视图填充完整的项目来查看,请始终以min height或“wrap_content”进行。

谢谢

在你的RecyclerView xml中添加这个:

 android:nestedScrollingEnabled="false" 

我已经通过使用下面的代码解决了这个问题:

  myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false){ @Override public boolean canScrollHorizontally() { return true; } @Override public boolean canScrollVertically() { return true; } });