实现美团首页滑动效果

滑动前后效果

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white"
    android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/ctlCollapsingLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|snap">
            <!--上面跟着滚动的布局-->
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <!--里面需要包含可滚动的布局,如果这里是ViewPager的话,里面的Fragment也需要有可滚动的布局-->
    </LinearLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

其他问题:
1.如果设置app:layout_scrollFlags="scroll|snap"的话头布局下面会有一个阴影分割,
解决办法:改为app:layout_scrollFlags="scroll|exitUntilCollapsed"就不会出现分割的阴影。

2.如果想要标题栏不跟着滑动,试了AppBarLayout的部分子view设置 app:layout_scrollFlags=“noscroll”,设置之后整个头布局都不会跟着滚动布局滚动了。
解决办法:把标题布局放在activity中,activity中有个静态的fragment,其余布局放在fragment中就可以了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值