Last active
May 29, 2019 02:07
-
-
Save amirulzin/6230090fcd0e59801107f7ef5bc7d041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package android.support.constraint; | |
import android.content.Context; | |
import android.os.Build; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/** | |
* Custom Group for ConstraintLayout that also supports alpha | |
*/ | |
public class CustomGroup extends Group { | |
public CustomGroup(Context context) { | |
super(context); | |
} | |
public CustomGroup(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public CustomGroup(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
public void updatePreLayout(ConstraintLayout container) { | |
int visibility = this.getVisibility(); | |
float elevation = 0.0F; | |
if (Build.VERSION.SDK_INT >= 21) { | |
elevation = this.getElevation(); | |
} | |
for(int i = 0; i < this.mCount; ++i) { | |
int id = this.mIds[i]; | |
View view = container.getViewById(id); | |
if (view != null) { | |
view.setVisibility(visibility); | |
// getAlpha() came from the inherited View class, and can be defined in CustomGroup XML via android:alpha | |
// or programmatically via setAlpha() | |
view.setAlpha(getAlpha()); | |
if (elevation > 0.0F && Build.VERSION.SDK_INT >= 21) { | |
view.setElevation(elevation); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
or in code: