首页 > 解决方案 > ConstraintSet如何清除constrainMaxHeight?

问题描述

我有一个ConstraintLayout并且我正在通过使用添加一个 maxHeight 约束constraintSet.constrainMaxHeight(R.id.recyclerView, (Utils.getScreenHeight() / 2.2).toInt())

稍后在我的执行中,我需要删除这个最大高度约束,所以我这样做:

constraintSet.connect(R.id.recyclerView, TOP, PARENT, TOP)
constraintSet.constrainHeight(R.id.recyclerView, MATCH_CONSTRAINT)
constraintSet.constrainMaxHeight(R.id.liveFeedRecyclerView, UNSET)

但是,我的 recyclerView 仍然具有分配给它的“最大高度”。取消设置最大高度约束并将我的视图高度设置为匹配约束的正确方法是什么?

PS:所有的常量值都是在ConstraintSet类中找到的常量。

标签: androidkotlinandroid-constraintlayoutconstraintset

解决方案


看起来ConstraintLayout将最大高度默认为Integer.MAX_VALUE(十进制值为 2147483647),因此请尝试使用它而不是UNSET-1。

在此处输入图像描述


推荐阅读