Android: 9-patch image not stretching as expected
Asked Answered
J

2

9

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

Janiuszck answered 19/10, 2012 at 15:8 Comment(3)
Its already there in the question. Thats where i set the imageView backgroundJaniuszck
Ive never known multiple lines to be used on the same side in a 9-patch. Have you tried it with just one. (I get that the preview is fine, but just to rule it out) radleymarx.com/blog/simple-guide-to-9-patchBleak
yeah i even tried with only 1 mark on the left side. same result :(. Even with 2 marks, the preview is perfect. moreover i dont have any problem with the height. Regarding the width it is getting stretched but weirdly :(Janiuszck
L
16

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

Likker answered 19/10, 2012 at 15:46 Comment(2)
My 9-patch Image is larger than the device screen in width. Thats why i get such a result??? I read: 9-patch images must be as small as possible because they can be stretched but cannot be shrinked. So, either i have to make the Image too small and then 9-patch it or set attributes as you suggested???Janiuszck
adjustViewBounds did itOrnithine
Y
2

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.

Yacketyyak answered 19/10, 2012 at 18:47 Comment(1)
My 9-patch Image is larger than the device screen in width. Thats why i get such a result??? I read: 9-patch images must be as small as possible because they can be stretched but cannot be shrinked. So, either i have to make the Image too small and then 9-patch it or set attributes as pcans suggested???Janiuszck

© 2022 - 2024 — McMap. All rights reserved.