问题描述
在哪里可以找到该视图/资源?我已经在几个应用程序上看到了。它应该公开一些隐藏的布局。
这是我谈论的视图/资源:
在这里,在灰色背景下,您还可以看到隐藏的布局:
解决方法
CoordinatorLayout
的子视图可以使用BottomSheetBehavior
启用“标准底表”特征。这样,我们可以处理底部锚点,上/下手势支持和动画状态转换等操作。
属性:
behavior_hideable
:确定在使用下拉手势时是否可以隐藏工作表(请记住,可以始终通过编程方式隐藏工作表)。对于“标准底板”,默认值为false;对于“模态底板”,默认值为true。
behavior_draggable
:确定在使用拖动手势时是否可以折叠/展开表格(请记住,需要实现自定义方式来展开/折叠表格)。默认值为true。
behavior_skipCollapsed
:确定隐藏工作表时是否应忽略折叠状态。如果behavior_hideable未设置为true,则这不会影响。默认值为false。
behavior_fitToContents
:确定展开的页面的高度是否包裹其内容。或者,它可以分为两个阶段:父容器的一半高度,父容器的整个高度。默认值为true。
behavior_halfExpandedRatio
:确定处于半展开状态的纸张高度(作为父容器高度的比率)。如果behavior_fitToContents未设置为false并且应大于窥视高度,则这不会影响。默认值为0.5(《材料准则》中的建议比例)。
behavior_expandedOffset
:确定处于展开状态时图纸从父容器顶部的偏移量。如果behavior_fitToContents未设置为false,并且在半展开状态下应大于偏移量,则这不会影响。默认值为0dp(工作表的顶部与父容器的顶部匹配)。
behavior_peekHeight
:工作表的初始“窥视”(折叠状态)高度。默认值为auto,它将在父容器的16:9比例关键行处设置窥视高度。否则,可以使用尺寸(或以编程方式设置像素值)。
现在执行:
layout_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
app:elevation="0dp"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
/>
</com.google.android.material.appbar.AppBarLayout>
<!-- Adding bottom sheet after main content -->
<include
layout="@layout/bottomsheet_layout" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
bottomsheet_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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="wrap_content"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="115dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="30dp"
android:scaleType="fitXY"
android:src="@drawable/frame_curved_border_top" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:background="@color/white">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="3dp"
android:fontFamily="@font/opensans_semibold"
android:text=" Siliguri - Gangtok (6123)"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="23dp"
android:layout_marginBottom="4dp"
android:fontFamily="@font/opensans_bold"
android:text="8:00 AM - 6:00 AM"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="23dp"
android:fontFamily="@font/opensans_semibold"
android:text="STNM Government"
android:textSize="13sp"
app:layout_constraintBottom_toTopOf="@+id/textView14"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:fontFamily="@font/opensans_bold"
android:text="Journey Updates"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:drawablePadding="8dp"
android:drawableTint="@color/light_grey"
android:fontFamily="@font/opensans_regular"
android:text="Driver started the journey"
android:textAlignment="center"
android:textSize="16sp" />
<View
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:background="#ddd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:drawablePadding="8dp"
android:drawableTint="@color/light_grey"
android:fontFamily="@font/opensans_regular"
android:text="Driver has left the bus stop (SNT)"
android:textAlignment="center"
android:textSize="16sp" />
<View
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:background="#ddd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:drawablePadding="8dp"
android:drawableTint="@color/light_grey"
android:fontFamily="@font/opensans_regular"
android:text="Driver is on the way"
android:textAlignment="center"
android:textSize="16sp" />
<View
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:background="#ddd" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
您可以将其用作 frame_curved_border_top.png
现在,您可以使用其他选择,例如MotionLayout
来在Android中获得相同的结果,这取决于您自己决定。而且,如果您只需要一个简单的FragmentDialog
实现而没有拖动效果,我也将使用该效果来更新答案。如果有帮助,请选择它作为答案。