首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RecyclerView在BottomSheetFragment中隐藏它下面的项

RecyclerView在BottomSheetFragment中隐藏它下面的项
EN

Stack Overflow用户
提问于 2021-11-04 10:28:03
回答 2查看 871关注 0票数 2

我使用的是带有自定义布局的BottomSheetDialogFragment。我正在尝试进行以下设置:

代码语言:javascript
运行
复制
<TextView> -> pinned to the top of the bottom sheet
<RecyclerView> -> wrap_content 
<Button> -> pinned to the bottom of the bottom sheet

TextViewButton必须在任何时候都是可见的(粘滞的),而RecyclerView应该保持在中间,滚动而不遮挡其他视图。

到目前为止,这是我的布局:

代码语言:javascript
运行
复制
<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中却以某种方式失败。

我已经看过其他的帖子了,但没有一篇对此有帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-05 13:15:51

最终成为解决方案的是将底部工作表的状态设置为扩展。

代码语言:javascript
运行
复制
val bottomSheetDialog = requireDialog() as BottomSheetDialog
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED

我认为底部的工作表从未完全展开,所以布局是不可见的。我以为底部页会根据内容的高度自动展开,但我错了。布局本身很好,我不需要对它做任何修改。

票数 0
EN

Stack Overflow用户

发布于 2021-11-04 10:37:50

回收商的高度不应该是wrap_content

如果您希望在标题和页脚之间重新定位,更好的方法是设置“高度”=0,并将其顶部固定在底部标题,将其底部钉在页脚的顶部(就像您已经做过的那样),它将自动为您进行拉伸。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69837756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档