解决ScrollView+RecyclerView的滑动冲突问题

764 阅读1分钟

项目中ui为一张置顶的imageView +recyclerView结构,当recyclerView滑动的时候,imageview不动,需求要是它们一体滑动,我们要这样来实现:

<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="match_parent"
        android:background="@color/white"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="216dp"
            android:scaleType="fitXY" />
        
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview_plan2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


    </LinearLayout>

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



然后我们在Activity中在加上一行代码就可以了:

RecyclerView.setNestedScrollingEnabled(false);


 这样滑动的问题就解决了。