android:visibility changes to children of MotionLayout

Turns out this was my inexperience with how MotionLayout works. By default MotionLayout controls the visibility of all views within it. But you can opt out child views by using the app:visibilityMode="ignore" attribute and defining the view in the <ConstraintSet>

In my case <CustomViewGroup1> looks like this…

<Constraint
      android:id="@id/CustomViewGroup1"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/HeaderBackground"
      app:layout_constraintVertical_weight="1"
      app:visibilityMode="ignore" />

And this is defined the same in both collasped and expended ConstraintSets as I don’t want it to move/animation when the recycler view is scrolled.

Thanks to John Hoford for the advice in another channel.

Leave a Comment