为什么底部工作表对话框无法在平板电脑上展开?

Osc*_*tor 2 android tablet android-studio bottom-sheet android-bottomsheetdialog

我在我的应用程序中实现了 BottomSheetDialog,但是当我将其安装在平板电脑上并将平板电脑放下时,第一次单击时它不会完全展开。它首先展开到“折叠”状态,您必须将其向上拖动才能看到所有内容。为什么要这样做?您可以根据自己的风格更改某些设置吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:behavior_peekHeight="0dp"
    >
   ...

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
val view = layoutInflater.inflate(R.layout.home_bottom_sheet_dialog, null)
val bottomSheetDialog = BottomSheetDialog(activity!!)

bottomSheetDialog.setContentView(view)
bottomSheetDialog.show()
Run Code Online (Sandbox Code Playgroud)

我将 API 22 AndroidX 与 kotlin 结合使用。

在此输入图像描述 在此输入图像描述

Osc*_*tor 6

正如Sinan Ceylan所说,这部分布局是不需要的。

应用程序:layout_behavior =“com.google.android.material.bottomsheet.BottomSheetBehavior”应用程序:behavior_peekHeight =“0dp”

但为了解决我的问题,我在显示之前将 BottomSheetBehavior 的PeakHeight变量设置为较大的值。

bottomSheetDialog.setContentView(view)
bottomSheetDialog.behavior.peekHeight = 1000
bottomSheetDialog.show()
Run Code Online (Sandbox Code Playgroud)

  • 在java中会是这样的:bottomSheetDialog.getBehavior().setPeekHeight(1000); (2认同)