0
<TextView
    android:id="@+id/tvTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Get Ready For"
    android:textSize="22sp"
    android:textColor="@color/colorAccent"
    android:textStyle="bold"
    android:textAllCaps="false"
    app:layout_constraintTop_toBottomOf="@id/toolbarExercise"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toTopOf="@id/readyflProgressBar"
    />

I want to change the constraints of this TextView programatically through kotlin. How do I do that?

3
  • if your textview constraints depends other layout components visibility you can use barrier. Commented Jan 23, 2022 at 21:35
  • I'm sorry, I don't understand Commented Jan 23, 2022 at 21:52
  • What's your condition? Commented Jan 23, 2022 at 22:46

1 Answer 1

0

This Works For Me

In My Xml :

 app:layout_constraintRight_toRightOf="@+id/view1"
 app:layout_constraintTop_toTopOf="@+id/view2" 

java

ConstraintLayout constraintLayout = findViewById(R.id.parent_layout);
     ConstraintSet constraintSet = new ConstraintSet();
     constraintSet.clone(constraintLayout);
     constraintSet.connect(R.id.otherView,ConstraintSet.RIGHT,R.id.view1,ConstraintSet.RIGHT,0);
     constraintSet.connect(R.id.otherView,ConstraintSet.TOP,R.id.view1,ConstraintSet.TOP,0);
     constraintSet.applyTo(constraintLayout);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.