我使用的是带有自定义布局的BottomSheetDialogFragment。我正在尝试进行以下设置:
<TextView> -> pinned to the top of the bottom sheet
<RecyclerView> -> wrap_content
<Button> -> pinned to the bottom of the bottom sheetTextView和Button必须在任何时候都是可见的(粘滞的),而RecyclerView应该保持在中间,滚动而不遮挡其他视图。
到目前为止,这是我的布局:
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Title"
app:layout_constraintBottom_toTopOf="@id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>这是一个小的项目列表的样子,在这个列表中RecyclerView不需要滚动。

这是一个庞大的项目列表的样子。标题仍然固定在顶部,但按钮没有。这个按钮实际上是看不见的,即使我一直向下滚动。

对我来说,奇怪的是,同样的布局适用于常规的全屏活动,但在BottomSheetFragment中却以某种方式失败。
我已经看过其他的帖子了,但没有一篇对此有帮助。
发布于 2021-11-05 13:15:51
最终成为解决方案的是将底部工作表的状态设置为扩展。
val bottomSheetDialog = requireDialog() as BottomSheetDialog
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED我认为底部的工作表从未完全展开,所以布局是不可见的。我以为底部页会根据内容的高度自动展开,但我错了。布局本身很好,我不需要对它做任何修改。
发布于 2021-11-04 10:37:50
回收商的高度不应该是wrap_content
如果您希望在标题和页脚之间重新定位,更好的方法是设置“高度”=0,并将其顶部固定在底部标题,将其底部钉在页脚的顶部(就像您已经做过的那样),它将自动为您进行拉伸。
https://stackoverflow.com/questions/69837756
复制相似问题