2017-08-23 4 views
-1

ConstraintLayout内のTextViewにいくつかの制約をプログラムで追加したいと思います。私はConstraintSetを使用しなければならないことを知っていますが、xml属性を追加する方法はわかりません:layout_constraintRight_toLeftOf(およびそれと同等のもの)をtextViewでJavaのアンドロイドに追加してください。アンドロイドでlayout_constraintRight_toLeftOfのプログラムに相当するものは何ですか?

ご協力いただければ幸いです!あなたはこのように設定することができます

+0

の可能性のある重複した[アンドロイド:どのようにプログラム的に設定するためのレイアウト\ _constraintRight \ _toRightOf "親"](https://stackoverflow.com/questions/41670618/android- how-to-programatically-set-layout-constraintright-torightof-parent) –

答えて

1

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); 
関連する問題