Set Alpha/Opacity of Layout

You can set the alpha on the layout and it’s children (or any other view for that matter) using AlphaAnimation with 0 duration and setFillAfter option.

Example:

AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
yourLayout.startAnimation(alpha);

You can use one animation for multiple components to save memory. And do reset() to use again, or clearAnimation() to drop alpha.

Though it looks crude and hacked it’s actually a good way to set alpha on set ov views that doesn’t take much memory or processor time.

Not sure about getting current alpha value though.

Leave a Comment