ImageButton 不显示特定的可绘制对象

发布于 2024-10-20 02:21:52 字数 633 浏览 3 评论 0 原文

这是我遇到过的一个相当有趣的问题,

我有一个带有 9 个图像按钮的表格布局,每行 3 个。每个 ImageButton 都有一个与之关联的不同图像。我已将图像按钮的背景设置为透明(#00000000)。现在有趣的事情发生了,其中一张图像没有显示在模拟器(Gingerbread)以及运行 Froyo 的设备上。布局编辑器显示所有图像。

这里还有一些东西:

  1. 我使用了 RelativeLayout 而不是 TableLayout,同样的问题仍然存在。
  2. 我改变了图像的位置(在不同的按钮上使用它),但它仍然没有显示。
  3. 当我使用不同的图像时,它们会出现,但当我使用这个特定的图像时,它们不会出现。
  4. 所有图像都具有相同的分辨率 (90x72) 和密度 (72ppi)
  5. 所有图像都位于 drawable-mdpi 文件夹中。

有什么指点吗?

编辑 原来是一个错误,这个问题已经解决了。请查看此链接

This is rather a funny problem I have ever come across,

I have a table layout with 9 image buttons, 3 per row. Every ImageButton has a different image associated with it. I have set the background of the image button to transparent (#00000000). Now here is where the funny stuff happens, One of the images doesn't show up on the emulator (Gingerbread) as well as a device running Froyo. The layout editor shows all the images in place.

Here are some more stuff:

  1. I used a RelativeLayout instead of a TableLayout, the same issue persists.
  2. I changed the position of the image (used it on different buttons) and still it doesn't show up.
  3. When I use a different image they show up, but when I use this particular image it won't.
  4. All images have the same resolution (90x72) and density (72ppi)
  5. All the images are in the the drawable-mdpi folder.

Any pointers?

EDIT
Turned out to be a bug and this issue has been resolved. Please check this link.

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

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

发布评论

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

评论(7

静水深流 2024-10-27 02:21:53

对我来说这是一个不同的问题。图像确实在 nexus4 和 nexus5 上显示,但在 nexus3 上不显示。我将图像从 2000 像素宽度缩小到 1000 像素宽度,效果非常好。

For me it was a different issue. The images did show on nexus4 and nexus5 but not nexus3. I scaled down the images from 2000px width to 1000px width and worked like a charm.

甜中书 2024-10-27 02:21:53

当您在设计面板中执行此操作时,您会得到类似这样的信息:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:srcCompat="@drawable/translate_button"/>

将最后一行手动更改为:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/translate_button"/>

它对我有用。

When you do it in DESIGN PANEL you get something like this:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:srcCompat="@drawable/translate_button"/>

Change the last line manually into:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/translate_button"/>

It worked for me.

寄风 2024-10-27 02:21:52

Do you still have the problem. I had a similar bug - a particular drawable was not being displayed, no matter in what `ImageView`.
Is it the case that your image is the first (alphabetically) in the drawable folder? For some strange reason there is a problem with the first drawable, I've solved my problem by adding a dummy drawable in first place. Still I'm very curious where the actual problem is.

Hope that helps! And I'm looking forward for any further explanations :)

Do you still have the problem. I had a similar bug - a particular drawable was not being displayed, no matter in what `ImageView`.
Is it the case that your image is the first (alphabetically) in the drawable folder? For some strange reason there is a problem with the first drawable, I've solved my problem by adding a dummy drawable in first place. Still I'm very curious where the actual problem is.

Hope that helps! And I'm looking forward for any further explanations :)

救星 2024-10-27 02:21:52

我可以确认添加一个按字母顺序首先显示的虚拟图像是一个解决方案。

我有一个图像(标题为 about.png,所以当然靠近可绘制文件夹的顶部),当使用的测试设备是 mdpi 时,该图像没有显示。

但就我而言,该图像不是目录中的第一个图像。实际上,我有一个按字母顺序首先显示的图像,名为 about_icon.png - 奇怪的是,它显示得很好。此外,图像的 hdpi 版本在 hdpi 设备中显示良好。

我添加了一个名为“aaaa.png”的虚拟占位符图像,现在有关图像的 mdpi 在设备中显示良好。

非常奇怪,而且老实说是一个非常糟糕的错误。

I can confirm adding a dummy image which displays first alphabetically is a fix.

I had an image (titled about.png so of course near the top of the drawable folder) which was not displaying when the test device used was mdpi.

In my case, though, the image was not the first in the directory. I actually had an image which alphabetically displayed first called about_icon.png - which oddly was displaying fine. Additionally, the hdpi version of the image was displaying fine within an hdpi device.

I added a dummy placeholder image called "aaaa.png" and now the mdpi about image displays fine in device.

Very strange, and honestly a pretty lousy bug.

粉红×色少女 2024-10-27 02:21:52

尝试使用 android:src="@drawable/my_resource",而不是 app:srcCompat="@drawable/my_resource"

Try to use android:src="@drawable/my_resource", instead of app:srcCompat="@drawable/my_resource".

寂寞美少年 2024-10-27 02:21:52

这篇文章相当老了,但我也遇到过类似的问题。运行 4.4.2 我的图像按钮会正确显示一些图像,但其他图像会改变。例如,我的白色“ic_camera.png”看起来像这样......在此处输入图像描述

什么似乎随机转动将图像放入其深色对应部分中。(我仔细检查了两次并三次检查是否放入了正确的颜色)所有图像均来自 Android 图标包。我尝试多次删除并复制回所有图像,但无济于事。最后,我只是更改了命名约定,删除了所有“ic”和“_”,以便图像全部为简单单词和小写字母。即...“camera.png”、“upload.png”和“newimage.png”

BINGO!
在此处输入图像描述

非常奇怪,但一个简单的修复。希望这对其他人有帮助!

干杯!

This post is fairly old however I was experiencing a similar issue. Running 4.4.2 my imagebutton's would show some images correctly however others it would change. For example my white "ic_camera.png" would look like this....enter image description here

What appeared to randomly turn images into their dark counter part.(I double and tripple checked that I put the right color in) All images came from the Android Icon pack. I tried deleting and copying back all images multiple times to no avail. Finally I just changed the naming convention, dropping all of the "ic" and "_" so that the images where all simple words and lower case. ie... "camera.png", "upload.png", and "newimage.png"

BINGO!
enter image description here

Very strange but a simple fix. Hope this helps someone else!

Cheers!

2024-10-27 02:21:52

对于任何提出这个问题并且答案不起作用的人,您的图像尺寸可能无法满足设备的目标尺寸...单击 此处获取正确的尺寸。

For anyone coming to this question and the answer does not work, your image size might not cater to the devices target size... click here to get the right sizes.

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