關(guān)于ScrollView嵌套多個(gè)RecyclerView滑動(dòng)沖突處理

  • Android的滑動(dòng)沖突可以說(shuō)是老生常談了舍沙,在項(xiàng)目中會(huì)遇到各種各樣的滑動(dòng)沖突問(wèn)題讼载,本遍文章主要對(duì)在ScrollView中多個(gè)RecyclerView的滑動(dòng)沖突的處理,當(dāng)然會(huì)有一部分使用第三部分上下拉刷新加載(SmartRefreshLayout,TwinklingRefreshLayout)的沖突的處理方式像街。(本次例子使用的是SmartRefreshLayout)

當(dāng)ScrollIView內(nèi)部只有一個(gè)RecyclerView的時(shí)候

<?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="這個(gè)是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

當(dāng)ScrollIView內(nèi)部有多個(gè)RecyclerView的時(shí)候

<?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="這個(gè)是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>

當(dāng)ScrollView嵌套多個(gè)RecyclerView時(shí)設(shè)置RecyclerView的android:nestedScrollingEnabled="false"筹裕,將滑動(dòng)事件交給父類(lèi)的ScrollView去處理,并且每個(gè)RecyclerView外面包上一層RelativeLayout椎木,設(shè)置如下屬性违柏,效果展示出下:

            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true"
MultiRecyclerView.gif

當(dāng)ScrollIView內(nèi)部只有一個(gè)RecyclerView的時(shí)候并且外部嵌套上下拉刷新控件

<?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="這個(gè)是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

當(dāng)ScrollIView內(nèi)部有多個(gè)RecyclerView的時(shí)候并且外部嵌套上下拉刷新控件

<?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="這個(gè)是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

以上為在ScrollView中嵌套R(shí)ecyclerView產(chǎn)生的滑動(dòng)沖突問(wèn)題的解決方案,如有不當(dāng)?shù)牡胤较阕担瑲g迎指正漱竖,謝謝

最后附上GitHub地址RecyclerViewInScrollView

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市畜伐,隨后出現(xiàn)的幾起案子馍惹,更是在濱河造成了極大的恐慌,老刑警劉巖玛界,帶你破解...
    沈念sama閱讀 218,036評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件万矾,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡慎框,警方通過(guò)查閱死者的電腦和手機(jī)良狈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)笨枯,“玉大人薪丁,你說(shuō)我怎么就攤上這事×源迹” “怎么了窥突?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,411評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)硫嘶。 經(jīng)常有香客問(wèn)我阻问,道長(zhǎng),這世上最難降的妖魔是什么沦疾? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,622評(píng)論 1 293
  • 正文 為了忘掉前任称近,我火速辦了婚禮第队,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘刨秆。我一直安慰自己凳谦,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布衡未。 她就那樣靜靜地躺著尸执,像睡著了一般。 火紅的嫁衣襯著肌膚如雪缓醋。 梳的紋絲不亂的頭發(fā)上如失,一...
    開(kāi)封第一講書(shū)人閱讀 51,521評(píng)論 1 304
  • 那天,我揣著相機(jī)與錄音送粱,去河邊找鬼褪贵。 笑死,一個(gè)胖子當(dāng)著我的面吹牛抗俄,可吹牛的內(nèi)容都是我干的脆丁。 我是一名探鬼主播,決...
    沈念sama閱讀 40,288評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼动雹,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼槽卫!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起洽胶,我...
    開(kāi)封第一講書(shū)人閱讀 39,200評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤晒夹,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后姊氓,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,644評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡喷好,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評(píng)論 3 336
  • 正文 我和宋清朗相戀三年翔横,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片梗搅。...
    茶點(diǎn)故事閱讀 39,953評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡禾唁,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出无切,到底是詐尸還是另有隱情荡短,我是刑警寧澤,帶...
    沈念sama閱讀 35,673評(píng)論 5 346
  • 正文 年R本政府宣布哆键,位于F島的核電站掘托,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏籍嘹。R本人自食惡果不足惜闪盔,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評(píng)論 3 329
  • 文/蒙蒙 一弯院、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧泪掀,春花似錦听绳、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,889評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至塔拳,卻和暖如春贴妻,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背蝙斜。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,011評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工名惩, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人孕荠。 一個(gè)月前我還...
    沈念sama閱讀 48,119評(píng)論 3 370
  • 正文 我出身青樓娩鹉,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親稚伍。 傳聞我的和親對(duì)象是個(gè)殘疾皇子弯予,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容