如何指定按钮左侧图像的尺寸?

发布于 2024-10-08 20:24:34 字数 344 浏览 0 评论 0原文

我想将图像放在带有一些文本的 Button 上,例如:

--------------
[image] [text]
--------------

我们可以使用 Button 执行此操作,并指定左侧的 Drawable,但它使用可绘制对象的“内在”大小。如果我理解正确的话,这在不同密度的设备上不起作用。如果我的图像是 32x32 像素,那么它在 hdpi 设备上看起来会非常小。有什么方法可以指定可绘制对象的宽度和高度(以 dp 为单位),以便它在不同设备上占用相同的空间量?

I would like to put an image on a Button with some text, like:

--------------
[image] [text]
--------------

We can do this with Button, and specify the left Drawable, but it uses the "intrinsic" size of the drawable. If I understand correctly, this won't work across different density devices. If my image is 32x32 pixels, it will look really small on hdpi devices. Is there any way to specify the width and height of the drawable, in dp, so that it will take the same amount of space on different devices?

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

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

发布评论

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

评论(1

唔猫 2024-10-15 20:24:34

这是正确的。您需要图像的 hdpi、mdpi 和 ldpi 版本,只需将它们放在适当的可绘制文件夹中,操作系统就会处理其余的事情。

如果您需要更多资源方案,这里有链接信息。

This is correct. You need an hdpi, mdpi and ldpi version of the image and you just place them in the appropriate drawable folder and the OS will take care of the rest.

Here is a link to the resource scheme in case you need more info.

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