Reputation: 24423
This is the first time i use nine-patch image on my android app. It so stupit. When I preview on eclipse layout editor, it work. But when I build the application on real device (HTC Inspire 4g, HTC Explorer,...) it's not.
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shadow_border"
android:gravity="center"
android:padding="0dip" >
<TextView
android:id="@+id/itemdetail_textview_price"
style="@style/textview_nomalBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10"
android:textColor="#F00"
android:textSize="32dp" />
<TextView
android:id="@+id/itemdetail_textview_originalPrice"
style="@style/textview_nomalBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="$20"
android:textSize="32dp" />
</LinearLayout>
Is there any problem here?
UPDATED:
I am writing the app for Android 2.2 and above.
My Phones use Android 2.3
Upvotes: 1
Views: 8545
Reputation: 10266
The image I'm using has a shadow, and brilliantly I assumed that it ends before it reaches the last pixel of the image... and so didn't bother to enlarge the image by a pixel... (I know the 9 patch tool is doing this for me but I was in the middle of editing the image so I just added it there)
So the problem is The preview can handle pixels with alpha, the 9-patch tool can handle it as well, but the device cannot!
Upvotes: 0
Reputation: 10812
I tested it more deeply, and it seems that there are inconsistencies between the draw9patch tool, Graphical editor in Eclipse and the device. Nine-patches, that seem to work in the first two, do not work on the device - they silently fall back to BitmapDrawable, without reporting an error. Reproduces on my 2.3.5 device, as well as in 4.1 emulator. See this android bug: http://code.google.com/p/android/issues/detail?id=38941
Workaround is to draw single row of pixels, not just dots.
TIP: your image should be as small as possible. If you put two dots to the left or top region, it means, that you have two stretched areas and the area between them is kept unstretched. You can cut out the area from the first dot (excluded) to the second dot (included) and have only one dot, with a smaller image and the same result.
Upvotes: 1
Reputation: 7526
Remove two dots from bottom and right side because these side decides in how much space your content should be displayed.
and here is how the nine patches work in android
And Follow this tutorial when you create a nine patch image.
Upvotes: 13
Reputation: 24423
I solved it by my self but I don't understand why it works.
In nine-patch, I draw 2 line at the top and the left of image (see 2 black lines at the picture)
Upvotes: 4