您的位置:首页 > 移动开发 > Android开发

android 实现TabLayout吸顶,title悬浮效果

2018-03-13 10:39 375 查看
之前项目需要做这样的一个效果,小费周折实现后,设计居然不要了,很是心塞。
记录下来,万一设计大大又变卦了呢(心中十万个友好问候)?
下面是我的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"
andr
4000
oid: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=
来调控,很简单的。
这几个控件的使用 有很多资源,大家可以自行谷歌。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: