Android: adding Drawable to existing LayerDrawable

I have a LayerDrawable that I create with an array of Drawables from 5 Drawables. Now let me say that at runtime I want to add another Drawable to my LayerDrawable in response to the event. How do I do this without having to recreate the LayerDrawable, this time with the Drawables array of 6 Drawables? Thank.

+3
source share
2 answers

After creating a LayerDrawable, new Drawables cannot be added to it.

See the source for LayerDrawable : the drawables array is saved in mLayerState.mChildrenand set only in the constructor.

However, setDrawableByLayerId(..)it can be used to exchange an existing Drawable with a new one.

+4

Source: https://habr.com/ru/post/1794814/


All Articles