Android滚动多TAB悬浮头效果
16lz
2022-05-08
Android滚动多TAB悬浮头效果
- 先看效果图
- 思路
- 开始贴代码
先看效果图
最近公司项目要实现类似这个效果于是自己就写了个demo记录一下,以下主要贴代码,文末还会上传demo代码
思路
使用RecyclerView做下方的列表,tab使用TabLayout.至于悬浮折叠则使用CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout
开始贴代码
<?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" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ScrollingActivity"> <TextView android:layout_width="wrap_content" android:layout_height="?attr/actionBarSize" android:text="返回" android:gravity="center" android:layout_marginLeft="16dp" android:layout_marginTop="16dp"/> <com.scwang.smartrefresh.layout.SmartRefreshLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" app:contentScrim="@color/colorAccent" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <FrameLayout android:background="@color/design_default_color_primary" android:layout_width="match_parent" android:layout_height="180dp"> <TextView android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="假装是一张图" /> FrameLayout> android.support.design.widget.CollapsingToolbarLayout> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/colorPrimary" app:tabIndicatorColor="#FFFFFFFF" app:tabSelectedTextColor="#FF888888" app:tabTextColor="#FFFFFFFF"> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:text="tab1" android:layout_height="wrap_content"/> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:text="tab1" android:layout_height="wrap_content"/> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:text="tab1" android:layout_height="wrap_content"/> android.support.design.widget.TabLayout> android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content">android.support.v7.widget.RecyclerView> android.support.design.widget.CoordinatorLayout> com.scwang.smartrefresh.layout.SmartRefreshLayout>LinearLayout>
SmartRefreshLayout是第三方刷新库如果有需要可以使用其它实现了NestedScrollingParent, NestedScrollingChild的刷新库
其中RecyclerView的使用代码不再贴出。
FrameLayout那里可以根据自己需要放图或者其它内容,我这里懒得放图就弄了个带背景的布局
最后放个Demo下载地址
更多相关文章
- Sqlite在Android中的简单使用
- adb——Android的ADB工具使用
- Android(安卓)UI开发第三十九篇――Tab界面实现汇总及比较
- 四极管:Android开机logo制作
- Android(安卓)WebView中javascript和java的互相调用
- Android(安卓)am 指令的使用
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用