Android:9 块重复模式而不是拉伸

发布于 2024-09-17 18:09:24 字数 261 浏览 2 评论 0原文

我有一个 9 补丁图像文件,如下所示:

alt text

当我使用它时,它看起来像这样:

alt text

我真正想要实现的是中心的完整点重复而不是拉伸。我希望这是可能的。

I have a 9-patch image file which looks like this:

alt text

When I use it it appears like this:

alt text

What I actually wanted to achieve is the complete dot in the center repeated instead of stretched. I hope that it's possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

孤独患者 2024-09-24 18:09:24

我认为使用 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

热鲨 2024-09-24 18:09:24

...

更正:如果您希望橙色点重复,则使用 9 补丁将不会成功。 9补丁只能拉伸你告诉它拉伸的部分,其余区域保持不变。 9 patch PNG 没有重复模式。

您可能想研究 Bitmap 类。这里有一个tileMode您可以用来解决您的问题。

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/stripe_bg"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
        />

...

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.

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/stripe_bg"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
        />
合约呢 2024-09-24 18:09:24

首先确保将 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?

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