之前一段时间,项目里有让模仿钉钉的tabbar上下滑动实现次级菜单的效果。本着面向baidu的编程思维搜索了一圈,貌似没有找到,只找到一个IOS上的实现,先看一下最终要的效果是怎么样的吧。
图是别人的图,就是实现这个效果。然后想到了CoordinatorLayout 里面有方便实现这样的效果,开始撸代码。
先来布局xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:behavior_hideable="false"
app:behavior_peekHeight="60dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/llRoot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:id="@+id/rg_main_bottom"
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:checked="true"
android:gravity="center"
android:text="button1&