简体   繁体   English

NestedScrollView里面没有使用Recyclerview

[英]NestedScrollView not fling with Recyclerview inside

I have a layout like that: 我有这样的布局:

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

The result looks like Google play store: 结果看起来像Google Play商店: 在此输入图像描述

And I disabled NestedScrolling in horizontal Recycler view: 我在horizontal Recycler视图中禁用了NestedScrolling:

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

My problem: 我的问题:

The vertical recyclerview does not scroll fling, whenever ACTION_UP happen, the vertical recyclerview also stop scrolling. vertical recyclerview ACTION_UP不会滚动,每当ACTION_UP发生时, vertical recyclerview ACTION_UP也会停止滚动。

How can I nest vertical recyclerview inside nestedscrollview , and horizontal recyclerview inside vertical recyclerview like Playstore and keep the scroll smooth. 我怎么能窝vertical recyclerviewnestedscrollviewhorizontal recyclerviewvertical recyclerview像Play商店中,并保持滚动顺畅。

Solved: 解决了:

Using custom nested scroll view of @vrund purohit (code below), and disabled nestedscroll both vertical and horizontal recyclerview: 使用@vrund purohit的自定义嵌套滚动视图(下面的代码),并禁用nestedscroll垂直和水平recyclelerview:

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

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

ViewCompat.setNestedScrollingEnabled(recyclerView, false);

I had this same problem and I solved this issue by customizing NeatedScrollView . 我有同样的问题,我通过自定义NeatedScrollView解决了这个问题。

Here is the class for that. 这是上课。

MyNestedScrollView 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);
        }
    }
}

Happy coding. 快乐的编码。

在RecyclerView xml中添加:

android:nestedScrollingEnabled="false"

[RESOLVED] I have same issue with Horizontal recycleview. [已解决]我对Horizo​​ntal recycleview也有同样的问题。 Change Gradle repo for recycleview 更改Gradle repo for recycleview

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

Fixed bugs related to various measure-spec methods in update 修复了更新中与各种measure-spec方法相关的错误

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

I have found issue with 23.2.1 library: When item is match_parent recycle view fill full item to view, please always go with min height or "wrap_content". 我发现了23.2.1库的问题:当item为match_parent时,回收视图填充要查看的完整项目,请始终使用最小高度或“wrap_content”。

Thanks 谢谢

I've solved the issue by using below code: 我使用下面的代码解决了这个问题:

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

        @Override
        public boolean canScrollVertically() {
            return true;
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RecyclerView 不在 NestedScrollView 内滚动 - RecyclerView not scrolling inside NestedScrollView NestedScrollView 内的 RecyclerView 问题 - RecyclerView inside NestedScrollView issue NestedScrollView内的RecyclerView比RecyclerView滚动得更快 - RecyclerView inside NestedScrollView scroll faster than RecyclerView 在nestedscrollview的recyclerview内部的recyclerview的notifyDataChanged上,外部recyclerview滚动到顶部 - On notifyDataChanged of recyclerview inside a recyclerview in a nestedscrollview the outer recyclerview scrolls to top 检查nestedscrollview中的recyclelerview滚动状态 - Check recyclerview scroll state inside nestedscrollview 如何在 NestedScrollView 中限制 RecyclerView 的高度 - How to limit the height of a RecyclerView inside a NestedScrollView NestedScrollView中的RecyclerView - 不需要的滚动开始 - RecyclerView inside NestedScrollView - unwanted scroll to begin 使用NestedScrollView中的Multiple Recyclerview不会发生回收 - View Recycling not happens with Multiple Recyclerview inside NestedScrollView 嵌套滚动视图中的 recyclerview addOnScrollListener (endless scrolllistener) - recyclerview inside nestedscrollview addOnScrollListener (endless scrolllistener) Android在RecyclerView上猛扑动作 - Android fling actions on a RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM