类似京东、淘宝等二级悬停。
参考+实践
一、惯例先上效果图

二、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

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



