Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding constraints programmatically

What is the translation to java code of the following XML instructions used in a layout definition with a constraint layout?

app:layout_constraintBottom_toBottomOf="@+id/Button1"
app:layout_constraintTop_toTopOf="@+id/Button1"
app:layout_constraintLeft_toLeftOf="@+id/Button2"
app:layout_constraintRight_toRightOf="Button2"
like image 569
codeKiller Avatar asked Sep 25 '17 08:09

codeKiller


Video Answer


1 Answers

Here is an example of adding constraints programatically,

ConstraintLayout mConstraintLayout  = (ConstraintLayout)fndViewById(R.id.mainConstraint);
ConstraintSet set = new ConstraintSet();

ImageView view = new ImageView(this);
mConstraintLayout.addView(view,0);
set.clone(mConstraintLayout);
set.connect(view.getId(), ConstraintSet.TOP, mConstraintLayout.getId(), ConstraintSet.TOP, 60);
set.applyTo(mConstraintLayout); 

To know more details you can refer Constraint layout

like image 98
Kuls Avatar answered Sep 17 '22 23:09

Kuls