使用ConstraintSet
ConstraintSet constraintSet = new ConstraintSet();
ConstraintLayout constraintLayout = (ConstraintLayout) LayoutInflater.from(this).inflate(R.layout.activity_main, null);
constraintSet.clone(constraintLayout);
// START WORKS
//constraintSet.connect(R.id.text, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, 50);
// LEFT DOES NOT
constraintSet.connect(R.id.text, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 50);
constraintSet.connect(R.id.text, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 50);
constraintSet.connect(R.id.text, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP, 50);
constraintSet.connect(R.id.text, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 50);
constraintSet.applyTo(constraintLayout);
如果有人想重现,那里有一个小样本应用:https://github.com/martinbonnin/TestConstraintLayout/tree/master
任何人都知道我错过了什么?
答案 0 :(得分:0)
我不确定你要做什么。你的预期结果是什么。
但是... 你正在使用END和LEFT这有点奇怪。 通常你会使用START& END或LEFT& RIGHT