关于ScrollView嵌套多个RecyclerView滑动冲突,可以很流畅的滑动

首先不建议过多的嵌套,可以采取其他方式替换

当ScrollIView内部只有一个RecyclerView的时候

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--其它的View-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/header_view"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:text="这个是RecyclerView"
                android:textColor="#000"
                android:textSize="24sp"/>
        </LinearLayout>

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

OneRecyclerView.gif

当ScrollIView内部有多个RecyclerView的时候

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/scroll_view"
    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">

        <!--其它的View-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/header_view"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:text="这个是RecyclerView"
                android:textColor="#000"
                android:textSize="24sp"/>

        </LinearLayout>


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_one"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false"
                >

            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_two"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="30dp"
                android:layout_marginTop="30dp"
                android:nestedScrollingEnabled="false">


            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_three"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false">


            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

当ScrollView嵌套多个RecyclerView时设置RecyclerView的android:nestedScrollingEnabled="false",将滑动事件交给父类的ScrollView去处理,并且每个RecyclerView外面包上一层RelativeLayout,设置如下属性,效果展示出下:

 

            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true"

MultiRecyclerView.gif

当ScrollIView内部只有一个RecyclerView的时候并且外部嵌套上下拉刷新控件

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srlEnableHeaderTranslationContent="false"
        app:srlEnableLoadmore="true"
        >

        <com.scwang.smartrefresh.header.MaterialHeader
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <ScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <!--其它的View-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/header_view"
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:gravity="center"
                        android:text="这个是RecyclerView"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        >

                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</RelativeLayout>

OneRecyclerViewWithRefresh.gif

当ScrollIView内部有多个RecyclerView的时候并且外部嵌套上下拉刷新控件

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srlEnableHeaderTranslationContent="false"
        app:srlEnableLoadmore="true"
        >

        <com.scwang.smartrefresh.header.MaterialHeader
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <!--其它的View-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/header_view"
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:gravity="center"
                        android:text="这个是RecyclerView"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_one"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        >

                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_two"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="30dp"
                        android:layout_marginTop="30dp"
                        android:nestedScrollingEnabled="false">


                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_three"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false">


                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</RelativeLayout>

MultiRecyclerViewWithRefresh.gif



 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

修行者对666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值