1

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?

Morgoth
  • 4,139
  • 5
  • 35
  • 53
  • 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 Jan 04 '18 at 15:40
  • 1
    @Gonzalo, That's for the `LayerList` and not the individual layers. – Morgoth Jan 04 '18 at 16:17

1 Answers1

0

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

hohteri
  • 134
  • 1
  • 5