2017-10-10 15 views
1

私は、テキストビューを親の右端に以下のコードで追加しようとしています。しかし、それは動作していません。制約レイアウトでlayout_constraintEnd_toEndOfをプログラムで達成する方法は?

ConstraintSet constraintSet = new ConstraintSet(); 
    TextView mValue1 = new TextView(getContext()); 
    mValue1.setText("Value 1"); 
    mValue1.setId(R.id.rightLabel1); 
    addView(mValue1); 
    constraintSet.clone(this); 
    constraintSet.connect(mValue1.getId(), ConstraintSet.TOP, this.getId(), ConstraintSet.TOP); 
    constraintSet.connect(mValue1.getId(), ConstraintSet.END, this.getId(), ConstraintSet.END); 
    constraintSet.applyTo(this); 

答えて

0

私は、ルート制約レイアウトのIDを設定していないことに気付きました。 idを単に設定すれば、それは動作します。または

constraintSet.connect(mValue1.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); 

constraintSet.connect(mValue1.getId(), ConstraintSet.END, this.getId(), ConstraintSet.END); 

を変更すると、問題を解決します。

関連する問題