android - 为什么 Bottom Sheet 对话框无法在平板电脑上展开?

标签 android android-studio tablet 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>
val view = layoutInflater.inflate(R.layout.home_bottom_sheet_dialog, null)
val bottomSheetDialog = BottomSheetDialog(activity!!)

bottomSheetDialog.setContentView(view)
bottomSheetDialog.show()

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

enter image description here enter image description here

最佳答案

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

app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" app:behavior_peekHeight="0dp"

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

bottomSheetDialog.setContentView(view)
bottomSheetDialog.behavior.peekHeight = 1000
bottomSheetDialog.show()

关于android - 为什么 Bottom Sheet 对话框无法在平板电脑上展开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60252896/

相关文章:

android - 如何更改 XML 文件中的字体 android studio

java - 重新打开选项卡时,Android Studio 布局引用失效

android - 放大/缩放 980 像素宽的网页以在平板电脑/小屏幕设备上占据整个宽度

html - 在不使用媒体查询的情况下定位平板电脑

mobile - 使用 Modernizr 测试平板电脑和移动设备 - 征求意见

java - 在android中导入字体时出现空指针异常

java - bitmap.compress(Bitmap.compressFormat.JPEG,100, baos) 给我 java.lang.OutOfMemoryError

android - 无法解析 : com. android.support :support-compat: 25. 0.1.?

Android studio - 带有库项目的应用程序无法构建

java - 为什么单击微调器时调试报告会记录 "Attempted to finish an input event but the input event receiver has already been disposed"?