Image showing in Android Studio but not on phone

44.4k Views Asked by At

As you can see below this is what Android Studio shows:

enter image description here

However, when I run this app on my phone the List View shows with just a blank image (i.e - a space) above it where the "somewhere over the rainbow" should be.

The List View is working fine. It consists of one image view and 2 text views. (This image view is working if it helps). If any of this is possibly interfering then I will post the code here, but I find that hard to believe.

The one thing that I was unsure of was whether I could use relative view when defining the cells for the list view in the separate xml file. I don't see why not but it's the only thing that I could think of.

Basically Android studio shows everything working but on the phone/emulator it is not the case. Hence, I am finding it very hard to locate the problem.

I'm new to the Android development scene so go easy on me.

EDIT

The image is .png format and is located in the drawable folder. I also have another .png image in the drawable folder that seems to give no problems. Why is this the case? The original image is clearly not corrupt as it shows up in Android Studio

SOLUTION

Had to move image to "mipmap-xxhdpi" folder due to size

9

There are 9 best solutions below

4
On BEST ANSWER

I found same problem today . So first check height and width of image and based on it put image into different drawable folder. i.e If image size is 1280 x 840 than put image in drawable-xxhdpi folder.

5
On

I recently had this same question, can you check which folder it is in. For me the problem was putting it inside the drawable folder, whilst it should be drawable-nodpi

Also state what device you're seeing this problem, is this multiple devices?

Image not appearing on HTC One M8

Here are relevant answers.

0
On

An earlier duplicate question was asked (I don't have enough points to flag the question above as a duplicate) here and Lukap's suggestion of putting the drawable into a drawable-hdpi folder worked for me. Apparently the use of three drawable folders (-hdpi, -mdpi, -ldpi) used to be standard practice.

While putting the image into any of the mipmap folders also worked for me (and then of course changing android:src="@drawable/image" to android:src="@mipmap/image"), the Android Developer page for App Resources says that mipmap resources are for "Drawable files for different launcher icon densities". So putting images other than launch icons in a mipmap folder seems to work but does not follow Android convention.

It seems to me like a bug for the image to not display when in the only available drawable/ folder since others recommend using the drawable folder for all images that are not app icons. On the Android Developer page for Providing Resources, there is a section that discusses the approach Android uses for selecting the best matching resources using an example where several drawable resources are available.

To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:

drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/

And assume the following is the device configuration:

Locale = en-GB
Screen orientation = port
Screen pixel density = hdpi
Touchscreen type = notouch
Primary text input method = 12key

By comparing the device configuration to the available alternative resources, Android selects drawables from drawable-en-port.

If there is only one drawable/ folder, you would think the android "logic" would select the only available drawable resource.

0
On

I can confirm that putting bigger images into a higher HDPI folder works on the Samsung Galaxy S4 when viewing images.

The problem I had was that the drawable folder for the higher HDPI did not exist. But if you create a new folder and name it drawable-xxhdpi or drawable-(whateverxxxhdpi), place it in [path to your project folder]\app\src\main\res\, then place your image there, it should work.

0
On

if you use android:src or app:srcCompat use android:background instead:

android:background="@drawable/your_image"
3
On

I stumbled across the same issue and found the answer below: (Source: https://stackoverflow.com/a/40397892/7614252)

What I did to make it work is to change the automatic key assigned (populated via Drag/Drop ImageView) from app:srcCompat="@drawable/logo" to android:src="@drawable/logo" in Text tab to make it appear on both the emulator and the device e.g

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="75dp"
    android:id="@+id/logoImageView"
    android:scaleType="fitXY"
    android:scaleX="1.5"
    android:scaleY="1.5" />
0
On

I was having a similar issue. my image was displayed on the image but was not showing on my android device...

I changed

tools:srcCompat="@drawable/ic_wifi"

and replaced it with

app:srcCompat="@drawable/ic_wifi"
0
On

i had similar issue but this what i added to my manifest file <application //this solve it for me. android:hardwareAccelerated="false" // Add this if the previuos line didn't solve the problem android:largeHeap="true" android:theme="@style/AppTheme">

0
On

I was having this problem and I solved it by adding this in my imageView xml code

android:adjustViewBounds="true"