简体   繁体   English

Android上约束布局中的左边距不起作用

[英]Margin Left in Constraint Layout on Android does not work

I have tried to set the margins to a ConstraintSet into the ConstraintSet.LEFT anchor. 我试图将边距设置为ConstraintSetConstraintSet.LEFT锚中。 But it doesn't work. 但这是行不通的。 However when using the ConstraintSet.START anchor, it works. 但是,当使用ConstraintSet.START锚时,它可以工作。

I am using constraints programmatically, and I tried setting the margins with both ConstraintSet.connect , as in: 我正在以编程方式使用约束,并且尝试使用ConstraintSet.connect设置边距,如下所示:

(Does't work) (不工作)

set.connect(view.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, MARGIN);

(Works) (作品)

set.connect(view.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, MARGIN);

And, I also tried with ConstraintSet.setMargin , as in: 而且,我还尝试了ConstraintSet.setMargin ,如下所示:

(Doesn't work) (不工作)

set.setMargin(view.getId(), ConstraintSet.LEFT, MARGIN);

(Works) (作品)

set.setMargin(view.getId(), ConstraintSet.START, MARGIN);

您必须使用START和END

set.setMargin(view.getId(), ConstraintSet.START, MARGIN);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM