0

There is a HomeFragment and in the "onCreateView", I want to change the "layout_constraintTop_toBottomOf" of a view, Is it possible?

<VideoView
    android:id="@+id/videoViewMain"
    ...
    app:layout_constraintTop_toBottomOf="parent" />

<androidx.appcompat.widget.AppCompatToggleButton
    android:id="@+id/appCompatToggleButton"
    ...
    app:layout_constraintTop_toBottomOf="@+id/imageViewMain" />

Change

app:layout_constraintTop_toBottomOf="@+id/imageViewMain" 

to:

app:layout_constraintTop_toBottomOf="@+id/videoViewMain"

Tried code but doesn't work:

ConstraintLayout  constraintLayout = (ConstraintLayout)root.findViewById(R.id.imageViewMain);
AppCompatToggleButton appCompatToggleButton= root.findViewById(R.id.appCompatToggleButton);
constraintLayout.addView(appCompatToggleButton);
ConstraintSet   constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(appCompatToggleButton.getId(), ConstraintSet.BOTTOM, 
constraintLayout.getId(), ConstraintSet.BOTTOM, 0);
constraintSet.applyTo(constraintLayout);
Dekker1
  • 5,565
  • 25
  • 33
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108
  • Check this https://stackoverflow.com/questions/41670618/android-how-to-programmatically-set-layout-constraintright-torightof-parent – Suraj Bahadur Sep 17 '20 at 19:26
  • 1
    Does this answer your question? [Android : How to programmatically set layout\_constraintRight\_toRightOf "parent"](https://stackoverflow.com/questions/41670618/android-how-to-programmatically-set-layout-constraintright-torightof-parent) – null_override Sep 18 '20 at 10:16

0 Answers0