Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group in ConstraintLayout prevents setting ProgressBar visibility

I'm flattening my layouts by employing the new ConstraintLayout (1.1.2) but I can no longer control the visibility of a ProgressBar when it's in a group. Here's the simplest version of my layout XML file which reproduces the issue:

    <android.support.constraint.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- This group prevents me from hiding ProgressBar -->
        <android.support.constraint.Group
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:constraint_referenced_ids="imageLoadingSpinner" />

        <ProgressBar
            android:id="@+id/imageLoadingSpinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </android.support.constraint.ConstraintLayout>

I've introduced the Group in order to control some of the layout, although for simplicity I've left all that out. The essence of the bug is introducing the group prevents me from setting the ProgressBar's visibility to GONE.

The following code no longer hides the ProgressBar:

    find(R.id.imageLoadingSpinner).setVisibility(GONE);

To be clear, if I remove the group, as shown below, I can set the ProgressBar's visibility to GONE:

    <android.support.constraint.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- Commenting out this group allows me to hide ProgressBar -->
        <!--<android.support.constraint.Group-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--app:constraint_referenced_ids="imageLoadingSpinner" />-->

        <ProgressBar
            android:id="@+id/imageLoadingSpinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </android.support.constraint.ConstraintLayout>

I can't find any information about this issue. ProgressBar visibility issue is unrelated.

like image 772
Michael Osofsky Avatar asked Sep 03 '25 09:09

Michael Osofsky


2 Answers

While, as has been said, you can't change the visibility of just a single Group's child (and for that I find this widget much less helpful and fun), you can always set its alpha property.

So if you don't mess in any way with an alpha value of a view you want to hide, you can just do the following:

find(R.id.imageLoadingSpinner).setAlpha(0);

And I can't quite find a reason not to do this, except maybe the fact that the view will probably still be rendered and then all the rendered pixels will be converted to 0-alpha and thus will become invisible wasting a few clock's cycles, but in most cases it would be an exaggeration to consider this as a problem.

like image 170
Android developer Avatar answered Sep 05 '25 00:09

Android developer


I don't think it's an issue because essentially that's the use of the Group, according to the docs:

This class controls the visibility of a set of referenced widgets.

Also:

The visibility of the group will be applied to the referenced widgets. It's a convenient way to easily hide/show a set of widgets without having to maintain this set programmatically.

So you have to set the visibility on the group itself. I don't know what you use the group for, because you didn't specify, but maybe you should restructure to better take advantage of it, or get rid of it completely.

like image 26
Suleyman Avatar answered Sep 04 '25 23:09

Suleyman