1
votes

I would like to remove/hide a layer in a layer-list during runtime. How do I do this?

I built a solution that works, but it feels a bit hackish.

I replace the desired layer with a transparent image:

LayerDrawable layerDrawable = (LayerDrawable) res.getDrawable(R.drawable.ic_layer);
Drawable digit = res.getDrawable(R.drawable.ic_number_empty);
layerDrawable.setDrawableByLayerId(R.id.layer_digit, digit);

Is there a better way to do this?

1
I have never been in that situatio, but reading LayerDrawable documentation https://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html you could use some methods like setAlpha(), setOpacity() or setVisible() - Gonzalo
@Gonzalo, That's for the LayerList and not the individual layers. - Morgoth

1 Answers

0
votes

How about layerDrawable.findDrawableByLayerId(R.id.layer_digit).setAlpha(0)?