有什么用9patch PNG的?什么用、patch、PNG

2023-09-06 22:24:33 作者:初恋无限好只是死的早

我看了文章(Android开发者)在9patch PNG的Andr​​oid系统。但我没有得到什么才是真正的利用呢?如果我使用渐变图像,然后它会表现得一样9Patch PNG。

I read article (Android Developers) on 9patch PNG in Android. But I'm not getting what is the real use of it ? If i use Gradient Image then it is going to behave same as 9Patch PNG.

我讨论,我的图形设计师,他告诉我,这是相同的CSS使用图像重复。是不是这样呢?

I had discussion with my graphics designer, he was telling me that it is same as Image Repeat used in CSS. Is it so ?

- 谢谢

推荐答案

没有它是不一样的。

想想你想给一个新的面貌按钮。随着9patch方式,您只需设计您的按钮的设计,例如像一个图像编辑程序Photoshop和其保存为PNG文件。在这之后,你的Andr​​oid SDK的9patch PNG工具打开它,并确定了区域这将是伸展和可扩展性。这样做,你可以新的按钮设计,适用于你的任何大小的按钮的设计可以缩放到任意大小,而不缩放边角和边框,因为他们标记为不拉伸的。如果你会用的都是正常的png格式的全PNG进行调整以按钮的大小会有什么可能看起来非常难看。

Think about a button you want to give a new look. With the 9patch way you simply design your button's design in a image editing program like e.g. Photoshop and save it to a png file. After this you open it with the Android SDK's 9patch png tool and define the areas which going to be stretchable and scalable. Doing this you can apply you new button design to a button of any size as the design can be scaled to any size without scaling the corners and borders as they were marked not-stretchable. If you'll would use are normal png the whole png will be scaled to the button's size what will probably look very ugly.

当然,你还得取决于渐变的类型(如线性)照顾的设计有渐变背景,因为他们可能只是伸展在方位(水平或者垂直)中。

Of course you'll have to take care of designs with a gradient background as they might only be stretchable in on orientation (horizontal or vertical) depending on the type of gradient (e.g. linear).

即使CSS图象重复属性是非常相似的9patch巴作为后者更容易使用,你只定义并将其应用到一个按钮。使用CSS,你就不得不考虑更多关于你如何做一个按钮,可扩展的。想想带圆角的按钮,你会怎么做这个用CSS? CSS的图像重复属性单独将完成这项工作,你会怎么有些定义角落留下始终是相同的,不应缩放或重复。

Even if the CSS image repeat attribute is very similar to the 9patch png as the latter one is easier to use as you only define and apply it to a button. With CSS you'll have to think much more about how you make a button scalable. Think about a button with round corners, how would you do this with CSS? The CSS image repeat attribute alone would do the job, you would how some define that the corners stay always the same an should not be scaled or repeated.