sebap123
sebap123

Reputation: 2685

9-patch png doesn't want to stretch properrly

I am having some weired problem with 9-patch image in my android app.

I want to make a line across a screen with a simple png. After creating 9-patch from it I've simply added it as a drawable to ImageView container. Unfortunatelly it doesn't want to stretch and still has this same dimmensions. Because I've never used 9-patch png I have no idea what am I doing wrong and also searching in Google is not so helpful, because there are only info, how you can make one, now how you can use it.

This is my code fragment from xml file:

<ImageView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:src="@drawable/testpng" />

and this is a image I want to add: enter image description here

Upvotes: 0

Views: 339

Answers (3)

sebap123
sebap123

Reputation: 2685

I found an answer to my question. The missing thing was one line of code android:scaleType="fitXY".

Now it looks like this

<ImageView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:scaleType="fitXY"
 android:src="@drawable/testpng" />

Upvotes: 0

Phant&#244;maxx
Phant&#244;maxx

Reputation: 38098

Well, if it's just a simple line,you wouldn't need a 9 patch...
Just use a View, give it a color as a background and give it a 1 px dimension:

<!-- Horizontal line -->
<View
    android_layout_width="match_parent"
    android_layout_height="1px"
    android:background="#ffff"
/>

<!-- Vertical line -->
<View
    android_layout_width="1px"
    android_layout_height="match_parent"
    android:background="#ffff"
/>

For the Shadowed line:

I'm using it so:

<View
    android:layout_width="match_parent"
    android:layout_height="2px"
    android:layout_centerVertical="true"
    android:background="@drawable/line_h"
/>

and this is line_h.9png, as small as I could make it (6*4 px) ;)

enter image description here

Now, this doesn't show in my graphical layout editor, but it does at run time!

Upvotes: 2

Alessandro Roaro
Alessandro Roaro

Reputation: 4733

Check that the extension of your file is .9.png. If it isn't, it's not recognized as a 9-patch.

Upvotes: 1

Related Questions