androidxmlandroid-layout

Responsive layout to visibility gone


I have a 3 components in xml. linearProgress, tvQuestionNumber, tvQuestion.

TvQuestion's some part is here:

<TextView
    android:id="@+id/tvQuestion"
    app:layout_constraintTop_toBottomOf="@id/linearProgress" />

When the linearProgress visibility become gone. I want to change like:

<TextView
        android:id="@+id/tvQuestion"
        app:layout_constraintTop_toBottomOf="@id/tvQuestionNumber" />

How can I make it responsive like that.


Solution

  • After you set the visibility to GONE, add

    ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) tvQuestion.getLayoutParams();
    layoutParams.topToBottom = R.id.tvQuestionNumber;
    tvQuestion.setLayoutParams(layoutParams);