在xml里写的layout_constraintWidth_percent=“0.4”
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.4"
在java中可以这样写
mConstraintLayout = (ConstraintLayout) findViewById(R.id.myconstraint_layout)
ConstraintSet set = new ConstraintSet();
set.connect(子view的id, ConstraintSet.TOP, ConstraintLayout的id, ConstraintSet.TOP); set.constrainPercentHeight(子view的id, 0.4); set.constrainPercentWidth(子view的id, 0.4);
set.applyTo(ConstraintLayout对象实例);