Search code examples
androidnine-patch

multiple view 9-patch sizing issue


I have a layout with a root as a custom RelativeLayout and within there some arbitrary Views. In my code i programmatically add some new Views and set a background supplied by the attributes in the onCreate() in my custom RelativeLayout. I add a nine-patch drawable from xml in my layout xml.

Now up until this point everything works fine when a View (in my case a TextView with a width of WRAP_CONTENT) is added. The problem arises when i try to add a second one which is shorter then the first one. The background of the first one now all of a sudden starts to match the size of the second one.

I tried mutating the drawable using mutate(), but there's no difference, probably because you have to call that when you actually do some operation on the drawable.

Any thoughts?


Solution

  • I Fixed reading the drawable id instead of the drawable itself. When inflating my views i set the background with the previously mentioned drawable id and it all works fine.