Android:9 块重复模式而不是拉伸
我有一个 9 补丁图像文件,如下所示:
当我使用它时,它看起来像这样:
我真正想要实现的是中心的完整点重复而不是拉伸。我希望这是可能的。
I have a 9-patch image file which looks like this:
When I use it it appears like this:
What I actually wanted to achieve is the complete dot in the center repeated instead of stretched. I hope that it's possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为使用 9-Patch 不可能制作重复的图案(仅拉伸某些区域),也许您可以在官方 文档
I think it's not possible using 9-Patch to make repeated patterns (only stretching certain area), perhaps you could find more about it in official documentation
...
更正:如果您希望橙色点重复,则使用 9 补丁将不会成功。 9补丁只能拉伸你告诉它拉伸的部分,其余区域保持不变。 9 patch PNG 没有重复模式。
您可能想研究 Bitmap 类。这里有一个tileMode您可以用来解决您的问题。
...
Correction: If you want the orange dots to repeat, you will not succeed using 9 patch. 9 patch can only stretch the part you told it to stretch and leave untouched, the remaining areas. There is no repeat mode with 9 patch PNG.
You might want to look into Bitmap class. There is a tileMode you might be able to use for your problem here.
首先确保将 9 补丁图像保存为 your_image_name.9.png 并将其存储在 res/drawable 文件夹中。然后在你的 xml 中设置布局背景 - android:background="@drawable/your_image_name" 就可以了。如果仍然不起作用,您可以发布您的布局 xml 吗?
First make sure you save your 9 patch image as your_image_name.9.png and store it in the res/drawable folder. Then in your xml just set the layout background with-- android:background="@drawable/your_image_name" and that should work. If it's still not working can you post your layout xml?