使用CoordinatorLayout+TabLayout+ViewPager實(shí)現(xiàn)折疊懸停布局

直接上代碼

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/c_f2f2f2"
    android:orientation="vertical"
    tools:context=".ui.activity.MainActivity">

    <View
        android:id="@+id/root_status_view"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

    <TextView
        android:id="@+id/tv_home_title"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/root_status_view"
        android:background="@color/white"
        android:gravity="center"
        android:text="叮當(dāng),為人類健康服務(wù)"
        android:textColor="@color/c_e77c81" />

    <View
        android:id="@+id/view_line1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/tv_home_title"
        android:background="@color/c_f2f2f2" />

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/rl_to_commit"
        android:layout_below="@+id/view_line1"
        android:layout_marginBottom="10dp">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/c_f2f2f2">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="false"
                app:contentScrim="@color/c_f2f2f2"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <include layout="@layout/item_home_top_view" />

                </RelativeLayout>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

            <com.androidkun.xtablayout.XTabLayout
                android:id="@+id/xl_Tablayout"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_marginTop="10dp"
                android:background="@color/white"
                app:xTabBackgroundColor="@color/transparent"
                app:xTabDisplayNum="4"
                app:xTabDividerWidthWidthText="true"
                app:xTabIndicatorColor="@color/c_e94544"
                app:xTabIndicatorHeight="4dp"
                app:xTabIndicatorRoundX="2dp"
                app:xTabIndicatorRoundY="2dp"
                app:xTabMode="scrollable"
                app:xTabSelectedTextColor="@color/c_e94544"
                app:xTabSelectedTextSize="13sp"
                app:xTabTextColor="@color/c_333333"
                app:xTabTextSelectedBold="true"
                app:xTabTextSize="13sp" />

        </com.google.android.material.appbar.AppBarLayout>

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/vp_home"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <RelativeLayout
        android:id="@+id/rl_to_commit"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginBottom="20dp"
        android:background="@drawable/shape_home_price_bg">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical">


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="10dp"
                    android:text="合計(jì):¥"
                    android:textColor="@color/white"
                    android:textSize="11sp" />

                <TextView
                    android:id="@+id/tv_shop_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="2dp"
                    android:text="0.00"
                    android:textColor="@color/white"
                    android:textSize="14sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tv_shop_num"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="7dp"
                    android:text="共0件"
                    android:textColor="@color/white"
                    android:textSize="11sp" />
            </LinearLayout>

            <TextView
                android:id="@+id/tv_shop_event"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="4dp"
                android:text="*活動(dòng)物品請(qǐng)?jiān)诘陠T處領(lǐng)取"
                android:textColor="@color/c_858a9e"
                android:textSize="9sp" />
        </LinearLayout>


        <TextView
            android:id="@+id/tv_commit_order"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="15dp"
            android:background="@drawable/shape_commit_bg"
            android:gravity="center"
            android:text="去結(jié)算"
            android:textColor="@color/white" />


    </RelativeLayout>

</RelativeLayout>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末耿芹,一起剝皮案震驚了整個(gè)濱河市钮热,隨后出現(xiàn)的幾起案子背桐,更是在濱河造成了極大的恐慌崎溃,老刑警劉巖躏惋,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拄查,死亡現(xiàn)場(chǎng)離奇詭異菇怀,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)咽筋,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門帝美,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人晤硕,你說(shuō)我怎么就攤上這事悼潭。” “怎么了舞箍?”我有些...
    開(kāi)封第一講書人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵舰褪,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我疏橄,道長(zhǎng)占拍,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任捎迫,我火速辦了婚禮晃酒,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘窄绒。我一直安慰自己贝次,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布彰导。 她就那樣靜靜地躺著蛔翅,像睡著了一般敲茄。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上山析,一...
    開(kāi)封第一講書人閱讀 52,457評(píng)論 1 311
  • 那天堰燎,我揣著相機(jī)與錄音,去河邊找鬼笋轨。 笑死秆剪,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的爵政。 我是一名探鬼主播鸟款,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼茂卦!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起组哩,我...
    開(kāi)封第一講書人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤等龙,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后伶贰,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體蛛砰,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年黍衙,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了泥畅。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡琅翻,死狀恐怖位仁,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情方椎,我是刑警寧澤聂抢,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站棠众,受9級(jí)特大地震影響琳疏,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜闸拿,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一空盼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧新荤,春花似錦揽趾、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)励七。三九已至,卻和暖如春奔缠,著一層夾襖步出監(jiān)牢的瞬間掠抬,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工校哎, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留两波,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓闷哆,卻偏偏與公主長(zhǎng)得像腰奋,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子抱怔,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360