Android : How to programmatically set layout_constraintRight_toRightOf “parent”
Here is an example of setting a button to the bottom of parent view using java code: ConstraintLayout constraintLayout; ConstraintSet constraintSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); constraintLayout = (ConstraintLayout) findViewById(R.id.activity_main_constraint_layout); Button button = new Button(this); button.setText(“Hello”); constraintLayout.addView(button); constraintSet = new ConstraintSet(); constraintSet.clone(constraintLayout); constraintSet.connect(button.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.RIGHT, 0); constraintSet.constrainDefaultHeight(button.getId(), 200); constraintSet.applyTo(constraintLayout); } to … Read more