android 實現TabLayout吸頂,title懸浮效果

之前項目需要做這樣的一個效果,小費周折實現後,設計居然不要了,很是心塞。

記錄下來,萬一設計大大又變卦了呢(心中十萬個友好問候)?

下面是我的UI界面,醜了一點,湊合看看


一個activity 裏面嵌套兩個fragment,佈局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@color/white"
    android:orientation="vertical">

    <include layout="@layout/tilte"></include>
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="com.yihui.wealthe.widgets.FlingBehavior"
            android:fitsSystemWindows="true">
            <LinearLayout
                app:layout_scrollFlags="scroll"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
                

            </LinearLayout>
        </android.support.design.widget.AppBarLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.design.widget.TabLayout
                android:id="@+id/tablayout"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:background="@color/white"
                android:padding="5dp"
                app:tabIndicatorColor="@color/red"
                app:tabIndicatorHeight="1dp"
                app:tabSelectedTextColor="@color/red"
                app:tabTextColor="@color/black_87" />

            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </android.support.v4.view.ViewPager>
        </LinearLayout>

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

</LinearLayout>

利用coordinatorlayout +appbarlayout+tablayout 實現具體效果,

coordinatorlayout 裏面嵌套的佈局,添加

app:layout_scrollFlags="scroll"
的會滑動,然後用
app:layout_behavior=

來調控,很簡單的。

這幾個控件的使用 有很多資源,大家可以自行谷歌。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章