何时使用 9-Patch

发布于 2024-11-07 06:47:33 字数 509 浏览 6 评论 0原文

有没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2024-11-14 06:47:33

当您的图像需要流畅的宽度和/或高度时,最好使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文