1

I have a constraint app:layout_constraintStart_toStartOf="parent". Runtime I need to change this constraint to app:layout_constraintStart_toEndOf="@+id\myid" .

From my research i found only constraintSet.connect(viewid, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 50); . But how to achieve my requirements with this. Any idea on this?

1 Answer 1

1

This is in kotlin but it's barely different from Java.

  1. Give an ID to the rootLayout.
  2. Now, use this code:

    val constraintSet = ConstraintSet()
    constraintSet.clone(rootLayout) //Your rootLayout
    constraintSet.connect(
       yourView.id,                //ID of the view whose position you want to change
       ConstraintSet.START,      
       yourMyIdView.id,            //ID of the correspondent view
       ConstraintSet.END
    )
    constraintSet.applyTo(rootLayout) //Your rootLayout
    

ProTip : You can also animate the change by setting animateChange to true in rootLayout (XML) or you can use a Transition animation which I always prefer.

val transition: Transition = ChangeBounds()
transition.interpolator = AccelerateInterpolator() //Or Any other Interpolator
transition.duration = 700 //Duration
TransitionManager.beginDelayedTransition(rootLayout, transition) //Your rootLayout
constraintSet.applyTo(rootLayout) //Remember to put above 4 lines before this

You can further add Alpha animation it by using yourView.animate().alpha(1f).duration = 700 //1f (0 to 1) is the value and 700 is the duration.

Remember, it is barely different from Java, you just have to add ; at the end possibly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.