MaterialDesign5.0 中 CoordinatorLayout 和 AppBarLayoutjava
来制做悬停效果布局 。android
先看下栗子app
实现很简单 布局
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"
android:orientation="vertical"
tools:context="com.example.administrator.exampletest.MainActivity">
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_scrollFlags="scroll"
>
android:src="@mipmap/ic_launcher_round"
android:layout_width="wrap_content"
android:layout_height="25dp" />
android:src="@mipmap/ic_launcher_round"
android:layout_width="wrap_content"
android:layout_height="25dp" />
android:src="@mipmap/ic_launcher_round"
android:layout_width="wrap_content"
android:layout_height="25dp" />
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#f0f"
app:layout_scrollFlags="scroll"
>
android:background="#a3e2f6"
android:text="我是悬停的那个控件哦"
android:gravity="center"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="20dp" />
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
布局文件使用spa
CoordinatorLayout
标明内部须要监听事件.net
AppBarLayout
标记须要折叠的布局 code
在须要折叠布局中 标注xml
app:layout_scrollFlags="scroll"
须要在顶部停留的控件 就直接写就好了。blog
在须要监听滑动触发折叠的控件上 标注事件
app:layout_behavior="@string/appbar_scrolling_view_behavior"
简单实现就酱紫
小栗子