I am successfully building a 9patch drawable at runtime on Android 3.0+ using the excellent gist provided by Brian Griffey (found here).
Essentially I load the raw (no patches) graphic file from the network and the filename contains the cap insets that I need to use in order to scale the image accordingly. I then use these values with the class found above and apply the image as a background to a variety of elements (such as TextView
, ImageButton
, Button
, ViewGroup
, etc).
This works perfectly as you can see here:
However, running the same code on Android 2.3.x yields the result:
I've looked through the source code used in Android to parse a 9patch image (here and here) but have found no method of getting this to work correctly. I've tried just about everything I could throw at it to no avail.
For the record, the 9patch consists of three columns on each axis, one fixed, one stretchable and one fixed.
Here's hoping someone else has solved this problem before.
Thanks in advance.
EDIT I am only interested in duplicating this behavior on Android 2.3 and above (I originally had 2.x).
EDIT #2 This gist describes exactly what I'm trying to do + Source image:
EDIT #3 The size of the image is 22px/58px (width/height) and the insets are 14/6/14/6 (top/left/bottom/right).
NinePatchDrawable
that I then set as a background to theTextView
. – AmundsenDrawable.setBounds()
is someway related to this issue. – Symmetry