简体   繁体   English

如何在Android中使用9种补丁图像以不同的2密度(如mdpi,ldpi,hdpi)?

[英]How to use 9 patch images in android for different-2 densities(like mdpi,ldpi,hdpi).?

I am creating an android application in which I want multiple screen support.For these I have used 9 patch images. 我正在创建一个想要多屏支持的android应用程序。为此,我使用了9个补丁图像。

But my question is this whether using 9 patch images will be enough for different-2 density's devices or I will need to create different-2 9 patch images for varying densities(like mdpi,ldpi,hdpi). 但是我的问题是,使用9个斑块图像是否足以满足不同2密度设备的需要,或者我需要针对不同的密度(例如mdpi,ldpi,hdpi)创建不同2个9个斑块图像。

Thanks in advance 提前致谢

I recently found out myself in the same situation so let me pitch in and expand on what has been said already... 我最近发现自己处在同样的情况下,所以让我投身并扩展已经说过的话...

Yes, 9-patch images will scale, that's what they exist for. 是的,9色块图像可以缩放,这就是它们存在的目的。 But if you should use a 9-patch image for all screen densities, that depends on the image really. 但是,如果您为所有屏幕密度都使用9色块图像,那实际上取决于图像。 9-patch images are more commonly used, for instance, buttons. 9色块图像更常用,例如按钮。 You can have different sized buttons in your app and a 9-patch image will help deal with them, no matter how you size your button (as long as the 9-patch image is properly created). 您可以在应用程序中使用不同大小的按钮,并且无论您如何调整按钮大小(只要正确创建了9个补丁的图像),一个9个补丁的图像都将有助于处理它们。

But let's say your button design has some really round corners for the hdpi version. 但是,假设您的按钮设计在hdpi版本中确实有一些圆角。 You create your 9-patch image without messing the corners but when you look at it in the ldpi version, you'll realize your corners are too big for that low resolution. 创建9补丁图像时不会弄乱角落,但是在ldpi版本中查看它时,您会发现角落对于那种低分辨率来说太大了。 For this situation, you'll need a different 9-patch image with less round corners, that look better on that resolution. 在这种情况下,您需要一个圆角较少的9色块图像,在该分辨率下看起来更好。

So, the final answer is, it really depends on your image. 因此,最终的答案是,这实际上取决于您的图像。 If you can create a 9-patch image that looks good in all densities, than fine, use it, as you only need one image to handle all densities. 如果您可以创建一个9补丁图像,在所有密度下看起来都不错,那就好用了,因为您只需要一个图像即可处理所有密度。 But if it doesn't look good, because of corners, gradients, or whatever, than you'll need one 9-patch image for each screen density. 但是,如果由于拐角,渐变或其他原因导致效果不好,则每个屏幕密度都需要一张9色块的图像。

Hopefully it's clearer now. 希望现在更加清楚。

From documentation: nine patch 来自文档: 九个补丁

A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background. NinePatchDrawable图形是可拉伸的位图图像,Android会自动调整其大小以适应将其放置为背景的View的内容。 An example use of a NinePatch is the backgrounds used by standard Android buttons — buttons must stretch to accommodate strings of various lengths. NinePatch的一个示例用法是标准Android按钮使用的背景-按钮必须拉伸以容纳各种长度的字符串。 A NinePatch drawable is a standard PNG image that includes an extra 1-pixel-wide border. NinePatch可绘制对象是标准的PNG图像,其中包括一个额外的1像素宽的边框。 It must be saved with the extension .9.png, and saved into the res/drawable/ directory of your project. 它必须以扩展名.9.png保存,并保存到项目的res / drawable /目录中。

the answer is no. 答案是不。 you nine patch will scale between different screen size 您的九个补丁将在不同的屏幕尺寸之间缩放

Short answer is YES. 简短的回答是。 Check this: 检查一下:

By default, Android scales your bitmap drawables ( .png , .jpg , and .gif files) and Nine-Patch drawables ( .9.png files) so that they render at the appropriate physical size on each device. 默认情况下,Android会缩放位图可绘制对象( .png.jpg.gif文件)和Nine-Patch可绘制对象( .9.png文件),以便它们在每个设备上以适当的物理尺寸呈现。 For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. 例如,如果您的应用程序仅为基线,中等屏幕密度(mdpi)提供位图可绘制对象,则系统在高密度屏幕上会按比例放大它们,而在低密度屏幕上会按比例缩小它们。 This scaling can cause artifacts in the bitmaps. 这种缩放可能会在位图中导致伪影。 To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities. 为了确保位图看起来最好,您应包括不同分辨率的替代版本,以适应不同的屏幕密度。

from Android Developer Official Doc 来自Android开发者官方文档

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

相关问题 使用9个Patch图像而不是mdpi / ldpi / hdpi / xhdpi图像 - Use 9 Patch images instead of mdpi/ldpi/hdpi/xhdpi images 如何使用不同的密度(mdpi、hdpi、xhdpi、...) - How to use the different densities (mdpi, hdpi, xhdpi, …) android 可以使用九个补丁图像代替 hdpi,mdpi,ldpi - android Can nine-patch images be used instead of the hdpi,mdpi,ldpi Android:为什么要为ldpi,mdpi和hdpi创建特定图像? - Android: Why create specific images for ldpi, mdpi and hdpi? 我怎么知道我应该为不同的android res(hdpi,mdpi,ldpi)制作一张图片的大小? - how do i know how big i should make a picture for the different android res (hdpi,mdpi,ldpi)? 如何使用res文件夹的drawable-hdpi,drawable-mdpi,drawable-ldpi中存在的图像? - how to use images present in drawable-hdpi,drawable-mdpi,drawable-ldpi of res folder? 如何在Android资产文件夹中保留hdpi,mdpi,ldpi和xhdpi文件? - How to keep hdpi,mdpi,ldpi and xhdpi files in the Android asset folder? 如何在Android中计算LDPI,MDPI,HDPI,XXHDPI,XXXHDPI的dp - How to calculate dp for LDPI,MDPI,HDPI,XXHDPI,XXXHDPI in android 缩放ldpi,mdpi,hdpi和xhdpi的图像 - scale images for ldpi mdpi hdpi and xhdpi 如何在HDPI Android设备上强制使用LDPI图像? - How do I force the use of LDPI images on an HDPI Android device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM