先看效果图:
当界面开始滑动时,“用户名用户名”文字便会缩小折叠到ToolBar上。
要实现这个效果,需要用到以下几个控件:CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout+Toolbar+RecyclerView
布局文件代码如下:
<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"
tools:context=".PersonalHomepageActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@color/white">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@color/white"
app:expandedTitleGravity="bottom"
app:expandedTitleMarginStart="35dp"
app:collapsedTitleTextAppearance="@style/CollapsedTitleTextStyle"
app:expandedTitleTextAppearance="@style/ExpandedTitleTextStyle"
android:id="@+id/collapsing_toolbar_layout"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="246