何时使用 9-Patch
有没有 Android 开发者文档说明什么时候可绘制资源可以是 9 补丁?换句话说,是否有文档说“以下项目使用 9 补丁数据(如果有)”之类的内容?
通过探索和经验,我了解到 9 补丁图形应该用于
我很惊讶地看到 9 补丁当可绘制对象用于菜单图标和选项卡图标时,数据将被忽略。
Is there any Android developer documentation that says when drawable resources can be 9-patch? To put it another way, is there a document that says something along the lines of "the following items use 9-patch data, if available"?
From poking around and experience, I've learned that 9-patch graphics should be used for
- application launcher icons
- icons used in the "Add to Home screen" selection list for App Widgets, Wallpapers, and Folders
- desktop wallpapers and when otherwise using BitMaps, e.g. on canvases
- button graphics
- view backgrounds
I've been surprised to see that 9-patch data is ignored when drawables are used for menu icons and tab icons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的图像需要流畅的宽度和/或高度时,最好使用 9 块。
示例:在我的应用程序中,我有两个横跨视图底部的自定义按钮。由于屏幕尺寸可能有所不同,因此我使用了 9 个补丁来让按钮正确拉伸。
9-patches is best used when you have an image that needs a fluid width and/or height.
Example: In my app I had two custom buttons that stretched across the bottom of the view. Because screen sizes can differ, I used 9-patches to allow the buttons to stretch correctly.