2017-08-23 2 views
-1

Je voudrais ajouter des contraintes à un TextView dans un ConstraintLayout par programme. Je sais que je devais utiliser ConstraintSet, mais je ne sais pas comment ajouter l'attribut xml: layout_constraintRight_toLeftOf (et ses équivalences) sur ce textView en Java dans android.Quel est l'équivalent de layout_constraintRight_toLeftOf par programmation dans android?

Toute aide est appréciée !!

+0

double possible de [Android: Comment définir la mise en page programatically \ _constraintRight \ _toRightOf "parent"] (https://stackoverflow.com/questions/41670618/android- comment-programmer-set-layout-constraintright-torightof-parent) –

Répondre

1

Vous pouvez définir comme celui-ci,

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);