他们两个都是用来滑动的布局,两个用到一起难免会产生一些滑动的冲突,
一旦产生冲突就会影响到页面的美观,如何避免他们之间的冲突其实很简单,
一行代码就搞定了
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</ScrollView>
只需要在
MainActivity加上一行
rv.setNestedScrollingEnabled(false);
加上这一行就能完美的解决ScrollView和RecyclerView的滑动冲突了