I'm experimenting with "Constraint.Group"
and I've children views: A, B, C.
In code, "Constraint.Group".visibility = View.Gone
does work, but if I choose to do A.visibility = View.Gone
it does not take an effect on children view. Is this normal behaviour?
A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread).
Groups is used when you want to handle visibility or motion with all its view. The Group in ConstraintLayout is just a loose association of views. Guideline: A guideline is a visual guide that will not be seen at runtime that is used to align other views.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With