Android 关于NestedScrollView与RecyclerView的滑动冲突的最终解决方案

最近做项目的时候发现一个小问题,当NestedScrollView嵌套RecyclerView的时候回出现种种不适,

网上给出的解决方案,比如去除RecyclerView的滑动事件、修改NestedScrollView或者RecyclerView的属性,等,都不能完美的解决冲突,翻了一下之前的旧页面,得出了最终的解决方案:

利用 ViewPager+Fragment的嵌套承载解决冲突:

将NestedScrollView嵌套RecyclerView 改变为NestedScrollView嵌套ViewPager

将RecyclerView放入ViewPager当中的Fragment,完美的解决问题

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

            <android.support.v4.view.ViewPager
                android:id="@+id/csdn_shen_hai_na"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </android.support.v4.view.ViewPager>

        </android.support.v4.widget.NestedScrollView>
发布了54 篇原创文章 · 获赞 212 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_39731011/article/details/103660077