对于移动端,为了留出更多的空间来显示内容,我们在向上滑动视图的时候,总是希望,顶部工具栏和底部工具栏可以随着我们向上滑动的手势而自动隐藏。而当我们浏览完内容,向下滑动视图的时候,又希望工具栏可以自动显示出来响应我们操作。这是一种很好的交互模式,现在我们来看看这种交互怎么实现。
布局很简单,上部工具栏和下部工具栏,还有中间的一个scrollView,里面是一张图片。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="@+id/top_menu"
layout="@layout/top_menu"/>
<ScrollView
android:id="@+id/main_content"
android:layout_below="@+id/top_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="夏季女装爆款"
android:textColor="#ffffff"
android:background="#000000"
android:textSize="20sp" />
<ImageView
android:id="@+id/photo_pic"
android:layout_below="@+id/title"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/clothes"/>
<RelativeLayout
android:layout_below=