gpt4 book ai didi

java - 在android中以编程方式相当于layout_constraintRight_toLeftOf的是什么?

转载 作者:行者123 更新时间:2023-12-02 12:20:12 25 4
gpt4 key购买 nike

我想以编程方式向 ConstraintLayout 内的 TextView 添加一些约束。我知道我必须使用 ConstraintSet,但我不知道如何在 textView 上添加 xml 属性:layout_constraintRight_toLeftOf (及其等效项) > 在 Android 中的 Java 中。

感谢任何帮助!!

最佳答案

可以这样设置,

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(layout); // root layout

// If you want to align parent to the layout left
constraintSet.connect(textView.getId(), ConstraintSet.LEFT, layout.getId(), ConstraintSet.LEFT);

// If you want to align to the left of one more textview - second text view
constraintSet.connect(textView.getId(), ConstraintSet.RIGHT, textView1.getId(), ConstraintSet.LEFT);

/*______________________________
| Text1 Text2 |
| |*/
constraintSet.applyTo(layout);

关于java - 在android中以编程方式相当于layout_constraintRight_toLeftOf的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45848269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com