View.GONE does not work on "Constraint.Group" specific children
Update: The behavior of individual view visibility within a group has been change and is reported as fixed in ConstraintLayout version 2.0.0 beta 6. See bug fixes for ConstraintLayout 2.0.0 beta 6 .
It does look like group visibility trumps the visibility of individual views of the group. This makes sense since each view has some visibility defined (GONE
, VISIBLE
, INVISIBLE
) so, if an individual view's visibility setting was honored, the integrity of the group would be violated. In other words, the individual view we changed the visibility of would, in essence, not be part of the group.
If you use above 2 version of constraint layout, you should use isGone property.
group.isGone = true
But if you use version lower than 2, it doesn't work due to some bugs.
I agree with Cheticamp and would like to add that you've got to toggle visibility individually as he said, or either create a general group to change all views inside and a local group to change only a specific view, like below:
<ImageView
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<ImageView
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<android.support.constraint.Group
android:id="@+id/group1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="view1,view2" />
<android.support.constraint.Group
android:id="@+id/group2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="view1" />
It won't be possible to change a single view visibility that is inside a group, but this way you can change group1 visibility or group2 visibility.