简体   繁体   English

9补丁图像在错误的位置缩放

[英]9 patch image is scaled at the wrong positions

I am using a nine patch image as a drawable for a selector's item element. 我使用九个补丁图像作为选择器项目元素的drawable。 The nine patch image is here: 九个补丁图像在这里:

9补丁图片

The image that finally gets rendered is this (emulator & device screenshot, both device have resolutions > mdpi): 最终渲染的图像是这个(模拟器和设备截图,两个设备都有分辨率> mdpi):

生成渲染图像

As you can see, it has been scaled outside the stretchable area (as defined in the 9 patch file), the darker green bar is much thicker as it should be. 正如您所看到的,它已经在可伸展区域之外缩放(如9补丁文件中所定义),较暗的绿色条纹应该更厚。 Why is that and can it be avoided? 为什么这样,可以避免吗? The draw9patch tool scales this image correctly. draw9patch工具正确缩放此图像。 Does it have to do with Android trying to preserve physical dimensions on high resolution devices? 是否与Android试图在高分辨率设备上保留物理尺寸有关?

Do you only provide a mdpi version of the image? 你只提供图像的mdpi版本吗?

Android scales all images that aren't available in the correct pixel density. Android会按正确的像素密度缩放所有不可用的图像。 This happens before the image is scaled via 9patch. 这是在通过9patch缩放图像之前发生的。

This would mean that your image gets scaled up to fit hdpi and then scaled to fit the content. 这意味着您的图像会按比例放大以适合hdpi,然后缩放以适合内容。

To fix this, you have to provide hdpi and xhdpi versions of your image. 要解决此问题,您必须提供图像的hdpi和xhdpi版本。 9patch isn't supposed to target different pixel densities and rather different content/screen sizes. 9patch不应该针对不同的像素密度和相当不同的内容/屏幕尺寸。

I checked out your 9 patch: 我检查了你的9补丁:

在此输入图像描述

Why did you color your not used bounds white? 为什么你把未使用的边界变成白色? It should be transparent. 它应该是透明的。 Because of this it is not recognized as a 9Patch: 因此,它不被认为是9Patch:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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