为什么我们需要9个补丁? [英] Why do we need 9-patch?

查看:90
本文介绍了为什么我们需要9个补丁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题就像标题中所说:为什么我们需要9个补丁的图像?他们真的那么重要吗?其实,他们真正在做什么?我没有清楚地了解9色块图像的概念.

My question is like title says: Why do we need 9-patch images? Are they really so important? Actually, what they really do? I don't get concept of 9-patch images clearly.

我知道9补丁图像是可伸缩的.因此,假设我有一些完全适合我的ldpi设备的图像按钮.使用Draw 9-patch工具(android SDK的一部分),我可以标记可扩展区域,并且该图像非常适合hdpi甚至xhdpi设备.边缘会很光滑.

I know that 9-patch images are scalable. So let's say I have some image button which perfectly fits on my ldpi device. With Draw 9-patch tool (part of android SDK) I can mark scalable areas and this image will nicely fit on hdpi and even xhdpi devices. Edges will be nice and smooth.

但是这真的是很好的实践,还是只是一种选择?我应该为ldpi,mdpi,hdpi和xhdpi设备创建每张图像,还是可以仅在一张图像上使用Android SDK绘制9-patch"并让Android处理各种设备?

But is this really good pratice or is just an alternative? Should i create every image for ldpi, mdpi, hdpi and xhdpi devices or can I just use Android SDK "Draw 9-patch" on one image and let Android handle various devices?

我不是很关心边缘,而是图片的实际内容.内容也可以扩展吗?

I'm not that concernet about edges, but the actual content of the picture. Is content scalable too?

推荐答案

在典型用法中,内容是可伸缩的,边缘将不会缩放.

The content is scalable, the edges will not be scaled, in typical usage.

它们通常用于按钮的背景或其他屏幕装饰,其中可缩放的内容可以无限缩放而不会丢失分辨率.

They're generally used for backgrounds to buttons, or other screen decorations, where the scaled content can be scaled infinitely without losing resolution.

理想情况下,它们在适当的情况下还用于 密度相关的资源,因此资源的部分(您未明确声明的部分是可扩展的)不会被扩展,随后像素化.

Ideally, they're used in addition to density-dependent resources where appropriate, so that the section of the resource (which you didn't explicitly state is scalable) isn't upscaled and subsequently pixelated.

考虑一下Android上Kindle应用程序的启动屏幕,该屏幕上有那个男孩在树上读书的剪影.在简化版本中,地面可以无限​​水平缩放,但是如果男孩被缩放,则他看起来会倾斜.因此,您可以使用九个补丁并指定可以缩放的部分以及向哪个方向缩放.

Consider the splash screen for the Kindle app on Android, which features a silhouette of that boy reading against a tree. In a simplified version, the ground can be scaled horizontally infinitely, but if the boy was scaled, he'd appear skewed. So you could use a nine-patch and specify the section which can be scaled, and in which direction.

但是,这还不够-如果仅包含低分辨率资源,则如果设备显示的密度较高,则该资源最初仍会按比例放大.在这种情况下,男孩可能会因为放大而显得模糊,这是更高分辨率的资源何时可以防止像素化的一个例子.

That's not enough though - if you only included a low resolution resource, the resource would still be scaled up initially if the device display was of a higher density. In this instance, the boy might look blurred from the upscaling, and is an example of when a higher resolution resource could have helped prevent the pixelation.

您对这个问题的表述方式(对我而言)暗示您正在询问9补丁图像是否可以替代所有可绘制资源,例如图标或其中包含图片的资源,答案是否定的.它们仅用于缩放具有单一颜色块的资源部分(即无法像素化的部分).

The way you've phrased the question suggests (to me) that you're asking whether 9-patch images can replace all drawable resources, like icons or resources with pictures in them, to which the answer is no. They're only to be used to scale sections of resources which feature a block of a single colour (i.e. sections which cannot be pixelated).

-

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

这篇关于为什么我们需要9个补丁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆