2017-10-10 2 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); 

을 변경하면 문제를 해결할 수 있습니다.

관련 문제