Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the alpha value for a ConstraintLayout group

Tags:

android

I want to ask is it possible to change the alpha for a constraint group?

<android.support.constraint.Group
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:constraint_referenced_ids="statusTv, statusDropDownIv"
    android:id="@+id/buttonGroup"
    android:visibility="visible"
    android:alpha="0" />

Right now the visibility tag has effect if I set it to visible/gone but the alpha tag seems to not work.

like image 327
Rgfvfk Iff Avatar asked Sep 24 '18 06:09

Rgfvfk Iff


2 Answers

Group is only used for controlling the visibility of Referenced Ids in app:constraint_referenced_ids. According to the documentation.

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.

like image 193
Faysal Ahmed Avatar answered Oct 06 '22 02:10

Faysal Ahmed


I created this extension function to help me achieve this functionality

fun Group.setAlphaForAll(alpha: Float) = referencedIds.forEach {
    rootView.findViewById<View>(it).alpha = alpha
}

And then in code I use it like this

my_group.setAlphaForAll(0.4f)
like image 35
Ahmad Melegy Avatar answered Oct 06 '22 03:10

Ahmad Melegy