Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View.GONE does not work on "Constraint.Group" specific children

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?

like image 646
MaaAn13 Avatar asked Apr 27 '18 08:04

MaaAn13


People also ask

Is constraint layout a view group?

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).

What is groups in constraint layout?

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.


3 Answers

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.

like image 56
Cheticamp Avatar answered Oct 04 '22 02:10

Cheticamp


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.

like image 20
Nicolas Pansardi Avatar answered Oct 04 '22 01:10

Nicolas Pansardi


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.

like image 27
Umut ADALI Avatar answered Oct 04 '22 01:10

Umut ADALI