10

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.

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
  • move images to "drawable" folder? obviously the problem is in image – Dmitry Ryadnenko Mar 03 '11 at 07:05
  • I can't do that. I have density specific images. Currently I am working on mdpi. And there is no reason for just one image to hide, while the others behave normally. – Ragunath Jawahar Mar 03 '11 at 08:03
  • but you can try to copy (not move) your images to drawable and see if the issue is still there. Can you see your image in LayoutEditor? – Tima Mar 03 '11 at 08:09
  • Yes, I can see the image (I am talking about only one particular image that causes the issue) on the Layout Editor and I have already mentioned it. I tried copying and moving the image to the 'drawable' folder but no use. It's still the same :( – Ragunath Jawahar Mar 03 '11 at 08:58
  • just an idea. your images are not selectors?! Have you tried it for another android versions (1.5, 1.6, 2.1)? – Tima Mar 03 '11 at 12:19
  • I tried them with Android 1.6, 2.1, 2.2 and 2.3 - Used as selectors as well as drawable resources. The name of the image is 'btn_about_normal', tried changing the name, etc., Nothing works. How funny! :D This is an issue I'm trying to resolve for my client. I also tried adding a few pixels to the image using photoshop. But still, the problem persists. – Ragunath Jawahar Mar 04 '11 at 06:28

7 Answers7

19

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 :)
Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
abikov
  • 205
  • 2
  • 6
  • Yes, I still do have this problem. Let me check what you have said and I'll report back on this. Thanks for your time. – Ragunath Jawahar Mar 15 '11 at 11:05
  • 1
    Thanks a lot @abikov. Exactly as you said. Now I have a dummy drawable in place. And everything works fine. This was driving me nuts for a few days. Thank you very much. – Ragunath Jawahar Mar 15 '11 at 11:13
  • Glad I could help. Yet I'm not sure when did this problem start to occur, and it's still interesting to me. – abikov Mar 15 '11 at 11:17
  • Had the same issue in a couple of apps. Thank God I found someone who had a similar issue :) – Ragunath Jawahar Mar 17 '11 at 08:18
  • 1
    This bug is documented as issue 20283: https://code.google.com/p/android/issues/detail?id=20283 – Niels May 10 '12 at 13:40
5

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

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
QuartZ
  • 154
  • 3
  • 12
5

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.

Pete Lada
  • 1,298
  • 10
  • 12
2

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!

kev
  • 2,306
  • 3
  • 26
  • 31
  • Oh man, this was exactly the cause in my case as well, you saved me hours of cursing...never would I figure this one out...Thanks! – Rok May 07 '14 at 13:33
  • This was my problem. Renaming from hamburger-white.png to hamburger_white.png solved it. This is even though the image shows up in the preview margin if I viewed the layout in xml! – Neil B Mar 16 '17 at 18:46
1

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.

Jacolack
  • 1,365
  • 2
  • 11
  • 25
0

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.

Foo Bar User
  • 2,401
  • 3
  • 20
  • 26
0

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.

Dmitry
  • 59
  • 3