Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding a 9 patch drawable at runtime
    primarykey
    data
    text
    <p>I am successfully building a 9patch drawable at runtime on Android 3.0+ using the excellent gist provided by Brian Griffey (found <a href="https://gist.github.com/briangriffey/4391807/6d4205d9be888bb57e8441dc6fabb898bddc0fb1" rel="nofollow noreferrer">here</a>).</p> <p>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 <code>TextView</code>, <code>ImageButton</code>, <code>Button</code>, <code>ViewGroup</code>, etc).</p> <p>This works perfectly as you can see here:</p> <p><img src="https://i.stack.imgur.com/KFiP6.png" alt="Android 3.0+ result"></p> <p>However, running the same code on Android 2.3.x yields the result:</p> <p><img src="https://i.stack.imgur.com/rlLQ8.png" alt="Android 2.x result"></p> <p>I've looked through the source code used in Android to parse a 9patch image (<a href="https://github.com/android/platform_frameworks_base/blob/master/include/androidfw/ResourceTypes.h#L45-L103" rel="nofollow noreferrer">here</a> and <a href="https://android.googlesource.com/platform/packages/apps/Gallery2/+/c2c0b01fbbf243eee1a11c33ba6dd1ce918a9ce5/src/com/android/gallery3d/ui/NinePatchChunk.java" rel="nofollow noreferrer">here</a>) 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.</p> <p>For the record, the 9patch consists of three columns on each axis, one fixed, one stretchable and one fixed.</p> <p>Here's hoping someone else has solved this problem before.</p> <p>Thanks in advance.</p> <p><strong>EDIT</strong> I am only interested in duplicating this behavior on Android 2.3 and above (I originally had 2.x).</p> <p><strong>EDIT #2</strong> This gist describes <a href="https://gist.github.com/deleet/f1f3ed7d3fd9ce7c3a78" rel="nofollow noreferrer">exactly what I'm trying to do</a> + Source image: <img src="https://i.stack.imgur.com/j8CE6.png" alt="source image"></p> <p><strong>EDIT #3</strong> The size of the image is 22px/58px (width/height) and the insets are 14/6/14/6 (top/left/bottom/right).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload