What is the proper way to use a 9-patch image resource on a custom view?
I'm doing this:
background = BitmapFactory.decodeResource(getResources(), R.drawable.fundo_bookshelf);
canvas.drawBitmap(background, null, new Rect(0, y, width, y+backgroundHeight), null);
fundo_bookshelf is a proper 9-patch image, saved as fundo_bookshelf.9.png, seen below:
But when using the drawBitmap, the whole image is stretched, instead of only the part with the black pixel on the top, as shown on this screenshot:
Something like this?
NinePatchDrawable bg = (NinePatchDrawable) resources.getDrawable(id);
if (bg != null) {
bg.setBounds(0, 0, getWidth(), getHeight());
bg.draw(canvas);
}
(sorry I didn't adapt it to your code, that is a straight cut/paste from my own, but hopefully enough to go on)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With