Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android nine-patch not being recognized on device

I just made a nine-patch

it is saved like border.9.png from the draw 9 patch tool.

in my android layout editor, it shows up like it is going to be a proper 9 patch graphic, stretched out yet not pixelated.

yet on a real device, it just shows a giant stretched image, with the 9patch guides seen, it looks really bad

whats going on??? and how do I fix it

my xml:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/border"
        android:orientation="vertical"
        android:padding="35dip" >
like image 597
CQM Avatar asked Dec 12 '11 19:12

CQM


People also ask

What is 9 patch image in Android?

The Draw 9-patch tool is a WYSIWYG editor included in Android Studio that allows you to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. Selected parts of the image are scaled horizontally or vertically based on indicators drawn within the image.

How to add image in XML Android Studio?

xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.

How to set image in drawable XML Android?

To use an image resource, add your file to the res/drawable/ directory of your project. Once in your project, you can reference the image resource from your code or your XML layout. Either way, it's referred to using a resource ID, which is the file name without the file type extension. For example, refer to my_image.

What is drawable folder in Android Studio?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.


2 Answers

I just had the same issue : everything worked fine in Eclipse but all where streched on the device. I solved it by opening the PNG in the Draw 9-patch tool. Just open the png and save it et voila !

like image 153
Alexandre MOINE Avatar answered Oct 21 '22 07:10

Alexandre MOINE


You can find all the necessary information how to create a 9.patch here

Your background should be like this

nine patch background

Note: the markers to the bottom and right need to be drawn as complete lines, not single dots.

Edit
Seems that uploading the 9.patch here becomes altered, and cannot be used as a 9.patch anymore.
You can download the functional version from here

like image 26
Gyuri Majercsik Avatar answered Oct 21 '22 07:10

Gyuri Majercsik