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. LocationManager

I'm trying to get some basic location code working, I've started from
the standard hello world type app, and have changed it to print the
current location. with the following code.

package com.android.tracker;

import android.app.Activity;
import android.os.Bundle;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.widget.TextView;

public class AndroidTracker extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       LocationManager lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);

       Location loc = lm.getLastKnownLocation("GPS");
       String pos = loc.toString();
       tv.setText(pos);
       setContentView(tv);
   }
}


However the getLastKnownLocation is returning null in the emulator.
Can anybody tell me what I'm doing wrong?

Thanks

Dave.

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

2. Album Art

Does anyone have a working Example of ALBUM_ART,  I have tried every
example out there and cannot find any that actually retreive the art.
the Lack of support on googles behalf on issues seems to be getting
greater as well
--~--~---------~--~----~------------~-------~--~----~

3. HSC SIPUA on android

4. Zoom from a point

5. Android Bug/Architectural Issue: How do I handle multiple versions of my own Content Provider?

6. - FTP client application for Androi

7. Is package name classloading conflict between applications possible ?