androidandroid-layoutandroid-widgetnine-patch

Influence of nine patch image non stretchable size on padding of component using it as background


I got a widget and when I use a color as a background, all the components inside have a 0 padding when I use android:layout_alignParentTop="true" (same for other sides).

But when I use a 9 patch image as the background of the parent, it seems to have a padding that is equal to the non stretchable size of the 9 patch image when I align them on their parent.

Is this normal ?


Solution

  • There are two main parts to a nine-patch: the stretchable areas and the content-defined areas. The top and left pixel border define the stretchable area, as I'm sure you're aware. The bottom and right, however, define the CONTENT area. If you want the padding to go away, you need to make the bottom and right bar extend all the way to the edge of the artwork (not all the way to the corner pixels, though!). Basically, the right and bottom pixel border define your padding.