android - 如何使用内部片段更改 CollapsingToolbarLayout 的高度?
问题描述
我有一个带有 CollapsingToolbarLayout 和内部片段的活动。CollapsingToolbarLayout 具有wrap_content高度。片段高度也设置为wrap_content。加载所有数据后,片段高度会发生变化,但 CollapsingToolbarLayout 的高度仍与以前一样。正因为如此,片段的一部分被剪切了,而其中的一部分对用户来说是不可见的。
我的想法是,在片段中我有观察者,当数据加载时,我通过监听器将测量的高度发送到活动。在那里我试图为片段设置 LayoutParams 并在片段和 CollapsingToolbarLayout 上使用invalidate()和requestLayout()方法,但它不起作用。
你知道如何解决这个问题吗?
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include layout="@layout/include_toolbar"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/other_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
片段.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contraints=".." />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/comments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contraints=".."/>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
推荐阅读
- java - 当我们 setUndecorated(true) 时,JFrame 不显示在多个屏幕中
- javascript - 行点击 react.js
- python - 如何使用 for 循环在 tkinter 中用空白帧填充屏幕设计的其余部分?
- postgresql - Postgres 过程/函数依赖
- codeigniter - 如何使用 codeigniter 在模式弹出窗口中显示点击数据?
- android - 如何通过匹配来自两个 API 的 id 来查看来自两个 JSON API 的响应到单个回收器视图适配器中?
- react-native - “焦点”听众不是每次都打电话。反应原生
- azure - Azure 数据库迁移服务卡在“正在进行日志传送”
- php - php动态关联数组显示来自mysql数据库的错误结果
- inheritance - 动态更改 SSRS 中报告的字段