Android实现上下滑动隐藏/显示工具栏

本文介绍如何在Android应用中实现上下滑动手势隐藏和显示顶部及底部工具栏。通过设置ScrollView滑动监听,动态调整工具栏的topMargin属性,结合动画效果,达到良好的用户体验。详细代码和实现可在提供的GitHub源码仓库中查看。
摘要由CSDN通过智能技术生成

对于移动端,为了留出更多的空间来显示内容,我们在向上滑动视图的时候,总是希望,顶部工具栏和底部工具栏可以随着我们向上滑动的手势而自动隐藏。而当我们浏览完内容,向下滑动视图的时候,又希望工具栏可以自动显示出来响应我们操作。这是一种很好的交互模式,现在我们来看看这种交互怎么实现。

布局很简单,上部工具栏和下部工具栏,还有中间的一个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=
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值