约束布局Y位置与边距值不匹配

问题描述 投票:0回答:1

我在运行时的视图上设置带有边距的约束时遇到了一些麻烦。

这些是向用户显示视图时的 y 和边距坐标 enter image description here

我这样设置边距:

    connect(
            chipsId,
            ConstraintSet.TOP,
            viewId,
            ConstraintSet.TOP,
        )

        connect(
            chipsId,
            ConstraintSet.BOTTOM,
            viewId,
            ConstraintSet.BOTTOM,
            145
        )

这给了我布局检查器的输出

enter image description here

边距设置为 145px。但是当你进行计算时,y 会减少到只有边距值的一半。 Y1 - Y2 = 472 - 399 = 73 =~ 145/2。

我不明白为什么 y 只从期望裕度的一半上升。我错过了约束布局中的某些内容吗? (我们使用的是最新的稳定版本:2.1.4)

谢谢你

android android-layout android-constraintlayout android-xml
1个回答
0
投票

很难理解实际问题,因为没有太多信息 - 不清楚你的布局(应该)是什么样子。

但问题似乎是您正在设置

chipsId
底部和
viewId
底部之间的参考下边距。

您能否至少分享一下带有

chipsId
的视图和
viewId
的视图 (xml) 规范吗?

根据订单,您可能需要将边距设置为从

TOP
BOTTOM
,例如像这样:

    connect(
        chipsId,
        ConstraintSet.BOTTOM,
        viewId,
        ConstraintSet.TOP,
        145
    ) 

这将导致

chipsId
底部和
viewId

顶部之间的边距为 145
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.