简体   繁体   中英

9patch images stretching incorrectly

在此处输入图片说明

( The black lines are not visible so I just made a replica of it in photoshop and enhanced the black lines for you people to understand. )

黑线是photoshop的。只是让它们看起来在这里有点可见。这只是一条放大线,使人们更容易理解。 **注意,我尚未使用PS

( The black lines are photoshopped. JUST so they look a bit visible here. )

Suppose, this is the 9patch image, i have broadened the 9patch black line in photoshop so its clearly visible.

This is how it is going to stretch. The logo remain in its original dimensions, only the blue space will stretch. In the 9patch software, the X and Y coordinate results were perfect and they stretch the way they should.

However, when I insert this in my xml code, I get this result.

在此处输入图片说明

WHY is the logo part stretching ? WHATEVER the dimensions of the layout may be, the logo should be in its right size , while the space around it SHOULD adjust , but its not happening so.

Edit:: The images in the jar preview fine, but when I actually use that resource in some layout, I get the incorrectly rendered result.

The xml code for the button :

<Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_normal" />

You do it wrong, To make a 9patch using photoshop :
1- add a new transparent 1-pixel in each image side (left, right, top and bottom)
2- draw the scaling and content in that transparent pixel (black color #000000), not over the image content it self.
3- save it as your_image_name.9.png

This is my version: logo.9.png

在此处输入图片说明

As you can see, it works just perfectly

在此处输入图片说明

Make sure you put it in the /res/drawable folder and it ends in .9.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM