Android 如何在 Photoshop 中创建 9 个补丁?什么是 9.png 编码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10653661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:30:51  来源:igfitidea点击:

How to create 9 patch in Photoshop? What is 9.png encoding?

androidphotoshopnine-patch

提问by Suzan Cioc

Provided utility looks bad, for example it does not allow to do "Save As", or to draw several button states with similar slicing.

提供的实用程序看起来很糟糕,例如它不允许执行“另存为”,或使用类似的切片绘制多个按钮状态。

Is it possible to draw 9.png in photoshop? I noticed, that generated png just contains black pixels in outer edge. Is this what is marking the slices?

是否可以在photoshop中绘制9.png?我注意到,生成的 png 只包含外边缘的黑色像素。这是标记切片的内容吗?

What if black pixels present in two opposite edges, how does this work?

如果黑色像素出现在两个相对的边缘,这是如何工作的?

Are outer edges cut off when displayed on android?

在android上显示时外边缘是否被切断?

回答by Kevin Coppock

Yes, I do all of my nine patches in Photoshop. Here are the basic rules for creating a 9-patch:

是的,我在 Photoshop 中完成了我所有的九个补丁。以下是创建 9-patch 的基本规则:

  1. The outer 1px margin can contain only 100% black (RGB 0, 0, 0) or fully transparent.

  2. The black pixels for the top margin and left margin define the stretch points, and must be either a solid line, a single point, or two separate points. If two points are defined, it will stretch equally between the two.

  3. The black pixels for the bottom margin and right margin define the content area. These pixels must be one contiguous line.

  4. When saving, be sure to append the .9.pngextension.

  1. 外部 1px 边距只能包含 100% 黑色 (RGB 0, 0, 0) 或完全透明。

  2. 上边距和左边距的黑色像素定义拉伸点,并且必须是实线、单个点或两个单独的点。如果定义了两个点,它将在两个点之间平均拉伸。

  3. 底部边距和右边距的黑色像素定义了内容区域。这些像素必须是一条连续的线。

  4. 保存时,请务必附加.9.png扩展名。

Hope this helps. :)

希望这可以帮助。:)

EDIT: And yes, those will not be displayed when used in your layouts, provided it's properly formatted and you've saved it as a .9.png.

编辑:是的,在您的布局中使用时不会显示这些内容,前提是格式正确并且您已将其另存为 .9.png。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Okay, so the top would be a simple nine patch for a spinner. the lines across and down in the second image show which rows/columns of pixels would be duplicated. The blue rectangle in the second image shows the area in which Android would allow content to be placed. So text, for example, would simply wrap to stay inside this rectangle.

好的,所以顶部将是一个简单的九个贴片供旋转器使用。第二张图片中的横线和横线显示哪些像素的行/列将被复制。第二张图片中的蓝色矩形显示了 Android 允许放置内容的区域。例如,文本将简单地换行以留在这个矩形内。