ScrollView与RecyclerView解决滑动冲突

在项目中遇到过ScrollView嵌套ScrollView滑动冲突,ScrollView嵌套ListView嵌套的滑动冲突,网上的方法太多解决方案,代码量都很大,所以我们现在可以用RecyclerView来替换点ListView,RecyclerView 嵌套RecyclerView是不存在冲突的 因为内部已经解决,ScrollVIew嵌套RecyclerView会存在现实不全的问题,滑动的时候会导致不流畅,所以我换用的是NestedScrollView嵌套RecyclerView不会存在显示不完全的现象,但是还会有一点的滑动冲突,下面我们来聊一聊解决方案。

我附上Xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="标题党"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
      
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

上面只是布局代码而已,滑动冲突还是没有解决,我们只要在recyclerView 设置一下这个属性就可以了
recyclerView.setNestedScrollingEnabled(false);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容