Android滚动多TAB悬浮头效果
16lz
2021-01-23
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下载地址
更多相关文章
- 实现三星S3蒲公英水波纹效果(二)——Renderscript准备篇
- Android实现底部tabbar按钮突出效果
- android应用安全——代码安全(android代码混淆)
- Android Studio如何设置代码自动提示
- 在Android中用纯Java代码布局
- 使用Android Studio调试Android Framework代码
- Android系列教程之六:TextView小组件的使用--附带超链接和跑马灯