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. Freelance Android Projects

Hi Developers,

If you are expert in 2D/3D , OpenGL on Android Platform and you are from
PAKISTAN, BANGLADESH, VIETNAM OR RUSSIA.
Please send  me you CV for {*filter*} Android based Projects with details of
your previously completed Android Projects.

*Note:* You must be good in 2D/3D, Advanced OpenGL , Java etc.


Regards,
argongold

-- 

2. can't select using touch after changing tabs on Froyo

Hi,

I have an activity with three tabs, the content is all in the same
activity. Here's how I setup the tabs:

tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(
                getResources().getText(R.string.tab1),
                getResources().getDrawable(R.drawable.ic_tab1))
                .setContent(R.id.tab1Content));

When I start the application the first tab is selected and touching
views works just fine. After I select the second tab, and afterwards
go to the first, selecting with touch no longer works. If I use the
trackball, selection works. If I select the third tab, touch selection
in tab1 and tab2 doesn't work anymore (trackball is OK). Touch
selection in the third tab works fine. I've tested this on my device
(Nexus One) and the emulator and the behaviour is the same. In Eclair/
Donut selection works fine.

Any ideas what might be causing this and how can I work around it if?

-- 

3. Flickering.

4. String Encryption on androi

5. Confusion in onItemClick and onListItemClick

6. Problems in use UTF-8 in the HTTP

7. gallery initial selection