Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: 9-patch image not stretching as expected

The actual image is this:

the red boxex are where i made 1 px black likes. Even the preview shows fine. So no problem with 9-patch

but the image i get for the following layout is:

<ImageView
    android:id="@+id/image_landing"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:background="@drawable/loginheader"
    android:contentDescription="@string/login_header"
     />

enter image description here

I Expected, the logo to be on the left and black dots on the right and the rest of the space between them is filled with grey color i selected on the top

Thank You

like image 565
Archie.bpgc Avatar asked Oct 19 '12 15:10

Archie.bpgc


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 do I create a 9 patch image in Photoshop?

Creating 9 patch background image using Photoshop:Draw the images in a regular way as you use to do in Photoshop. Make the 1px spacing around the image from all sides. And also make sure that the image doesn't have anything in this 1px area & has 100% transparency. Otherwise 9patch image will not work.

What is 9 patch?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.


2 Answers

Is your ImageView really bigger than your 9patch?
If not, you need to change scaleType as defaut is FIT_CENTER.

Use android:scaleType="fitXY" or android:adjustViewBounds="true".

like image 66
pcans Avatar answered Sep 21 '22 23:09

pcans


It looks like your 9 patch is larger than the ImageView that you are trying to put it in. Try setting the ImageView to wrap_content to see if it fixes the problem. If it does, try making the 9 patch smaller, the ImageView bigger or set the scaleType as pcans mentioned.

like image 20
starkej2 Avatar answered Sep 24 '22 23:09

starkej2