我在我的应用程序中实现了 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 结合使用。
最佳答案
正如 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/