CoordinatorLayout与AppBarLayout。置顶悬停,二级悬停,类似京东、淘宝等二级悬停。

类似京东、淘宝等二级悬停。
参考+实践


一、惯例先上效果图

效果图

二、GitHub

代码地址,欢迎指正https://github.com/MNXP/SlideTop

三、XML布局主要用到的控件

  1、PullRefreshLayout (借用这位大神的https://github.com/genius158/PullRefreshLayout)
  2、CoordinatorLayout
  3、AppBarLayout

四、实现

1、布局的实现
  需要注意的几点:
   1)AppBarLayout 设置 behavior 需要自己定义,为以后拦截事件用
      app:layout_behavior=".weight.MyBehavior"
   2)AppBarLayout 第一个子view,就是需要滑动消失的布局,设置
      app:layout_scrollFlags="scroll|exitUntilCollapsed"
      scroll  滚动,exitUntilCollapsed 可以在置顶后有阴影效果
   3)最外层RecyclerView(也可以是各种带滑动的view,也可以是ViewPager实现分页) 设置
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="60dp"
      android:background="#ffffff"
      android:orientation="vertical">

      <TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center"
          android:text="置顶滑动"
          android:textColor="@color/black"
          android:textSize="20sp" />
      <TextView
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:layout_alignParentBottom="true"
          android:background="#dddddd"/>
  </RelativeLayout>

  <com.xp.slide.weight.refreshlayout.PullRefreshLayout
      android:id="@+id/swipe_refresh_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:prl_pullDownMaxDistance="300dp"
      app:prl_twinkEnable="true">

      <androidx.coordinatorlayout.widget.CoordinatorLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@+id/home_top_view"
          android:orientation="vertical">

          <com.google.android.material.appbar.AppBarLayout
              android:id="@+id/app_bar_layout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="#ffffff"
              app:layout_behavior=".weight.MyBehavior">

              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
                  app:layout_scrollFlags="scroll|exitUntilCollapsed">
                  <ImageView
                      android:layout_width="match_parent"
                      android:la
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值