📜  Android 中 Modal 和 Persistent Bottom Sheet 的区别

📅  最后修改于: 2021-09-12 10:42:37             🧑  作者: Mango

Android BottomSheet是一种在移动应用程序中用作补充表面的视图。该组件是android 设计支持库的一部分,用于暴露更多数据或信息、菜单、深层链接内容以及代替对话框。它通过从应用屏幕底部向上滑动出现在屏幕上,用户可以在收到信息后隐藏它。在谷歌地图、音乐播放器等应用程序中,可以很容易地注意到BottomSheets。在现代Android 应用程序中,BottomSheets 有两种类型:

  1. 持久底片
  2. 模态底片

持久底片

Persistent BottomSheet显示 Android 底部工作表,就像活动/片段布局上存在的任何其他视图一样。顾名思义,它的存在是持久的,即它与应用程序主 UI 区域共存。它通过显示相关的应用程序内容并同时允许在该区域进行交互来为用户提供便利。开发人员使用此BottomSheet 来显示菜单、任何类型的辅助内容或应用程序的其他支持内容。

谷歌地图中的持久性BottomSheet:

持久底片

模态底片

这种 BottomSheet 的外观类似于alert-dialogdialog fragment 。之所以得名是因为它的行为和外观类似于Modals 。与 Persistent BottomSheet 不同,当用户请求某些操作时,它会从屏幕底部出现。激活后,它会隐藏主应用程序的活动/片段。工作表内容的高度高于应用程序(默认为 16dp ),并且包含与用户发出的操作请求或来自其他应用程序的深层链接内容相对应的选项列表。

Google Drive 中的 Modal BottomSheet(在单击“+”图标以将新项目添加到驱动器时出现):

模态底片

差异表

Persistent BottomSheet

Modal BottomSheet

Display content related to the application or current activity. Display content of other applications that are interlinked with the current app.
Always present at bottom of the app screen and display some content. When activated/clicked, it shows complete information.  Appear on the screen when a user clicks on certain action buttons. While poping up on the screen, it replaces the already present menu or dialogs.
It is a part of the activity view layout. It is not a part of an activity view layout but appears dynamically when the user demands.
Integrated into the app in order to display supporting content. Slides up from the bottom of the screen when needed.
The elevation of its appearance is the same as that of the application’s content. Its appearance has a higher elevation than the application’s content. Android dims and blocks the interaction with the main app to shift the focus of the user.  
BottomSheetBehavior(a kind of layout_behavior) is applied to a child of CoordinatorLayout in order to make it a Persistent bottom sheet. To make a bottom sheet of Modal design, BottomSheetDialogFragment is used on top of the Fragment support library. It renders the fragment acting as a dialog to a Modal bottom sheet.
To see more or less content, it can be dragged upward or downward respectively. Expose its content by dragging it vertically upwards. Tap the content outside the dialog to dismiss the bottom sheet.
To control its appearance, certain kinds of states are present such as STATE_COLLAPSED, STATE_EXPANDED, STATE_DRAGGING, STATE_SETTLING, and STATE_HIDDEN. No such states are present in it as the appearance is similar to an alert-dialog or dialog fragment.
想要一个更快节奏和更具竞争力的环境来学习 Android 的基础知识吗?
单击此处前往由我们的专家精心策划的指南,旨在让您立即做好行业准备!