android - 仅为一个 ConstraintLayout 链视图设置最大高度
问题描述
我在链式垂直链中有两个ConstraintLayout
视图spread_inside
。我只想layout_constraintHeight_max
为第一个视图设置最大高度,但由于它是链的头部,它适用于所有链式视图。
如何仅将最大高度约束应用于链的第一个视图?
解决方案
的这种行为layout_constraintHeight_max
是违反直觉的。尝试以下布局,它应该模拟一个没有烦人layout_constraintHeight_max
行为的链。它使用屏障来标记底部视图的顶部。
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/topView"
android:layout_width="200dp"
android:layout_height="0dp"
android:background="@android:color/holo_blue_light"
app:layout_constraintBottom_toTopOf="@id/barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="200dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="This is the top view." />
<TextView
android:id="@+id/bottomView"
android:layout_width="200dp"
android:layout_height="0dp"
android:background="@android:color/holo_red_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_min="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topView"
tools:text="This is the bottom view." />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="bottomView" />
</androidx.constraintlayout.widget.ConstraintLayout>
你说顶视图可以缩小到0dp
。如果您的意思是零高度,那么上述内容本身可能不会那么远。
推荐阅读
- python - ValueError:int() 的无效文字,基数为 10:“image_path”:“tflearn”包的image_preloader
- java - 为什么某些 VPN 客户端会破坏 Java 调试以及如何解决该问题?
- rest - 使用 webmethods 的 POST 请求
- angular - ngrx 效果:调度空动作
- amazon-web-services - 使用 AWS Cloudfront 缓存查询时如何向 api 添加简单许可
- python - pytest pep8 合规性检查卡住了
- java - Junit 测试方法 - 无法解析符号 '.ok()'
- inheritance - 如何更改 no_create:odoo 中的 False
- javascript - 配置 router.beforeEach
- javascript - JSGrid以编程方式选择第一行