Confused about 9-patch files

by craiget » Tue, 03 Mar 2009 10:26:47 GMT


Sponsored Links
 Can someone please explain or provide examples (links) of some valid 9-
patch files?


As an example, there's a 9-patch located at:  http://www.maladroid.net/test.9.png 

[the same idea, as abad ascii representation]

0 = transparent, 1 = black, 2 = red

010101010
102020200
102020200
102020200
102020200
000000000

So there are 3 single-red-pixel columns, with stretchable areas
defined between them. It seems like this should resize to any aspect
ratio and there will still be 3 single-pixel red columns. My thinking
is that the solid black border on the left means "scale uniformly in
the y-direction" and that a pixel in the top row above the transparent
columns means "scale the transparent area, but leave the red columns
with width=1 pixel".

Is that the correct interpretation of black/transparent pixels?

Using the draw9patch tool, it doesn't scale if I make the left-border
completely black, but if I remove any one pixel, then it scales - why
is that?

When working in Eclipse, after refreshing the /drawables folder,
sometimes my 9-patch doesn't show up in the R.java file, presumably
because it is somehow invalid. Yet, I can still refer to it and use it
in the Layout Editor. Am I correct to assume there's something wrong
with the 9-patch? Or perhaps there's something wrong with my (default
eclipse plugin) build process?

Thank you for any suggestions.



--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by deepdr...@googlemail.com » Wed, 04 Mar 2009 02:56:32 GMT


 You can find examples of 9patch files in the SDK, in tools/lib/res/
default/drawable/
The .9.png files are 9patches.

 http://www.deepdroid.com 




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Confused about 9-patch files

by Marco Nelissen » Wed, 04 Mar 2009 04:50:06 GMT


 


Because a ninepatch consists of 9 patches, only 5 of which are scaled,
while the 4 corners are not scaled. An image that has a black top-left
pixel therefore cannot be a ninepatch image. The draw9patch tool
shouldn't even let you set the top-left to black.

--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by Romain Guy » Wed, 04 Mar 2009 04:55:42 GMT


 > Because a ninepatch consists of 9 patches, only 5 of which are scaled,

Actually our 9patches really are n-patches. You can have as many
stretchable areas as you want.

-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by Dianne Hackborn » Wed, 04 Mar 2009 07:29:17 GMT


 A feature unfortunately added after the name itself was pretty set in stone.
:)






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by craiget » Wed, 04 Mar 2009 10:36:45 GMT


 Thank you for the replies.

Maybe what's causing my confusion is a bug in aapt (or my
environment?) rather than misunderstanding the concept of 9-patch. In
which case I may be posting to the wrong place.

I've got two files that demonstrate what's happening:

This first file, Eclipse likes and it successfully gets packaged into
the application and everything is fine.

 http://maladroid.net/b.9.png 

This second file is exactly the same, except it duplicates the pattern
of 1px red bars for one more column. This file seems to cause aapt to
crash. However, it seems like it should be a valid 9-patch.

 http://maladroid.net/c.9.png 

The console shows an error message:

 *** glibc detected *** /home/me/android/android-sdk-linux_x86-1.1_r1/
tools/aapt: realloc(): invalid old size: 0x09a50770 ***
[2009-03-03 21:21:15 - Test] ======= Backtrace: =========
~~~ etc



Any ideas what could be causing that to happen?

Thanks!










--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by Dianne Hackborn » Wed, 04 Mar 2009 11:23:26 GMT


 aapt should never crash, so it's a bug in it of some kind.  Unless you want
to dig in and figure out the problem, filing a bug report would probably be
good. :)








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by Marco Nelissen » Thu, 05 Mar 2009 01:07:15 GMT


 Are you sure that b.9.png works correctly? It doesn't seem to stretch
correctly either in the draw9patch tool.







--~--~---------~--~----~------------~-------~--~----~



Confused about 9-patch files

by Marco Nelissen » Thu, 05 Mar 2009 13:14:59 GMT


 It's a bug in aapt. Where you should normally be able to have up to
width/2 horizontal stretch regions, it only allocates enough space for
width/4. Your image was 36 pixels wide, so you can have 9, and it
would crash on 10 (like your c.9.png image).
The issue with draw9patch you mentioned earlier is separate issue,
which only affects rendering in draw9patch, but doesn't affect how
your ninepatch will look in your app.







--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Playing high quality youtube videos from my application

I managed to play (using videoView class) and control (using
MediaController class) youtube videos but I would like to play HQ
videos like the android dev1 does itself. Is it possible?

--~--~---------~--~----~------------~-------~--~----~

2. Can we do QVGA LCD with Android?

Dear all,

It is really worth that we do QVGA LCD with Android or not?

So far, i've never found the Android phone with QVGA LCD on MKT while
many rumours around this configuraion.

Furthermore, a lesson learning from KOGAN for Agora phone(original LCD
is QVGA) and delayed definitely and official excuse is QVGA
resolution. But i don't know what's the exact reason?

So who can tell me
1. what's the problem we will meet with Android+QVGA LCD?
2. what's the attitude from google for QVGA LCD under Android phone,
while QVGA was said to be supported from Google?

If QVGA is not recommended to be with Android, why there is no formal
info from Google to avoid any unvaluable try on this LCD?

--~--~---------~--~----~------------~-------~--~----~

3. How to properly pass MotionEvent to a worker thread

4. Google IO phone / 30 day Tmobile SIM

5. contest

6. How to properly pass MotionEvent to a worker thread

7. Buying Commercial Android Phone for Development