Android Override 9-patch padding in XML on the one hand

When using an image with 9 patches as the background, the indentation always seems to be inferred from the image with 9 patches. Even if you do not use the fill bar in 9 patch images, it uses a pop-up.

If padding lines are not included, Android uses the left and top lines to define this area for drawing.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

However, you can override it in XML using android: padding = 0dp or = Xdp. Unfortunately, using android: paddingLeft = Xdp does not work. So you are stuck with a uniform gasket. I tried to do this:

android:padding="2dp" android:paddingLeft="20dp" 

This did not affect the filling on the left. Placing them in the styles.xml file gave similar results.

The only hack I've seen to get around this is to install an add-on to the code.

+6
source share
1 answer

if (android: padding), it overrides all other values โ€‹โ€‹of the else if pad (android: paddingXXX), it overrides bg drawable paddingXXX (XXX = Left | Right | Top | Bottom) else if (view has drawable bg) indent values โ€‹โ€‹from of this drawable (nine patches in your case); otherwise, the default addition (usually zero) is applied

So do not use android: padding = "2dp". the padding property overrides everything. Just use paddingLeft = 20dp, paddingTop = 2dp, paddingRight = 2dp, paddingBottom = 2dp.

Or you can set paddingLeft = 20dp, and other padding values โ€‹โ€‹will be taken from bg drawable.

+7
source

All Articles