1

I'm trying to programmatically add/remove the android:layout_below="@+id/relativeLayout_progress_circles" attribute from the ConstraintLayout element. how do I do this?

  <android.support.constraint.ConstraintLayout
        android:id="@+id/my_constraint_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view1"
        android:layout_above="@+id/view2"
        android:layout_centerHorizontal="true"
        android:scaleType="centerInside">
...
/>
grassyburrito
  • 1,213
  • 22
  • 32
  • Please refer to this post: https://stackoverflow.com/a/45264822/9636037. – Abhimanyu Jun 03 '20 at 06:51
  • 3
    Does this answer your question? [ConstraintLayout: change constraints programmatically](https://stackoverflow.com/questions/45263159/constraintlayout-change-constraints-programmatically) – Abhimanyu Jun 03 '20 at 06:52

1 Answers1

0

Hey you can use the following code to dynamically apply this changes.

    ((RelativeLayout.LayoutParams)my_constraint_layout.getLayoutParams()).addRule(RelativeLayout.BELOW,view.getId());
    //Here my_constraint_layout is your constraint layout and view is the view below which you want to set your constraint layout.
Aashit Shah
  • 578
  • 3
  • 9
  • OP is asking about setting constraints programmatically to Constraint Layout. (Not Relative Layout) – Abhimanyu Jun 03 '20 at 06:54
  • 1
    He has used android:layout_centerHorizontal,android:layout_below so i guess his parent is RelativeLayout and he wants to move his constraint layout in his view hierarchy . But yes you can also be right . The question is ambiguous. – Aashit Shah Jun 03 '20 at 07:01