CoordinatorLayout配合viewpager的基本使用

先看效果

22.gif

主布局

<android.support.design.widget.CoordinatorLayout
        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.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="260dp">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:layout_scrollFlags="enterAlwaysCollapsed|scroll">

                <RelativeLayout
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="50dp"
                    app:layout_collapseMode="parallax">

                    <ImageView
                        android:id="@+id/image"
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="10dp"
                        android:src="@mipmap/ic_launcher" />

                    <TextView
                        android:id="@+id/tip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/image"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="7dp"
                        android:text="我是沙拉 不是能吃的沙拉" />
                </RelativeLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    app:contentInsetStart="0dp"
                    app:layout_collapseMode="none">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@android:color/white">

                        <TextView
                            android:id="@+id/titlename"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:text="個人中心"
                            android:textColor="@android:color/background_dark"
                            android:textSize="18sp" />

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

            </android.support.design.widget.CollapsingToolbarLayout>

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_collect"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/white" />
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/vp_collect"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </android.support.design.widget.CoordinatorLayout>

viewpager里的fragment布局

 <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tv_test"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="loading"
                android:background="#ff0000"/>
        </android.support.v4.widget.NestedScrollView>
        
    </FrameLayout>

填充viewpager

       MyFragmentPagerAdapter adapter = new 
       MyFragmentPagerAdapter(getChildFragmentManager(), fragmentList, titleList);
       bindingView.vpCollect.setAdapter(adapter);
       bindingView.vpCollect.setOffscreenPageLimit(2);
       adapter.notifyDataSetChanged();
       bindingView.tabCollect.setTabMode(TabLayout.MODE_FIXED);
       bindingView.tabCollect.setupWithViewPager(bindingView.vpCollect);
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末酷窥,一起剝皮案震驚了整個濱河市聂儒,隨后出現(xiàn)的幾起案子贞远,更是在濱河造成了極大的恐慌,老刑警劉巖蠢箩,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拱层,死亡現(xiàn)場離奇詭異虹菲,居然都是意外死亡憋肖,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門胰苏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來硕蛹,“玉大人,你說我怎么就攤上這事硕并》ㄑ妫” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵倔毙,是天一觀的道長埃仪。 經(jīng)常有香客問我,道長陕赃,這世上最難降的妖魔是什么卵蛉? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮么库,結(jié)果婚禮上傻丝,老公的妹妹穿的比我還像新娘。我一直安慰自己诉儒,他們只是感情好葡缰,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般泛释。 火紅的嫁衣襯著肌膚如雪滤愕。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天胁澳,我揣著相機與錄音该互,去河邊找鬼米者。 笑死韭畸,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的蔓搞。 我是一名探鬼主播胰丁,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼喂分!你這毒婦竟也來了锦庸?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤蒲祈,失蹤者是張志新(化名)和其女友劉穎甘萧,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體梆掸,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡扬卷,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了酸钦。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片怪得。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖卑硫,靈堂內(nèi)的尸體忽然破棺而出徒恋,到底是詐尸還是另有隱情,我是刑警寧澤欢伏,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布入挣,位于F島的核電站,受9級特大地震影響硝拧,放射性物質(zhì)發(fā)生泄漏财岔。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一河爹、第九天 我趴在偏房一處隱蔽的房頂上張望匠璧。 院中可真熱鬧,春花似錦咸这、人聲如沸夷恍。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽酿雪。三九已至遏暴,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間指黎,已是汗流浹背朋凉。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留醋安,地道東北人杂彭。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像吓揪,于是被迫代替她去往敵國和親亲怠。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

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