【发布时间】:2021-12-18 14:16:03
【问题描述】:
我正在使用带有自定义布局的BottomSheetDialogFragment。我正在尝试进行以下设置:
<TextView> -> pinned to the top of the bottom sheet
<RecyclerView> -> wrap_content
<Button> -> pinned to the bottom of the bottom sheet
TextView 和 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 而失败。
我已经看过其他帖子,但没有一个有帮助,例如
【问题讨论】:
-
感谢您的帮助。原来是底部工作表状态配置的问题,而不是布局问题。
标签: android android-layout android-recyclerview bottom-sheet