Reputation: 1559
Inside my AlertDialog I've an ImageView, when I choose to show the android:src="@drawable/logo_small"
(a png around 64x64px in every folders /hdpi /ldpi ect..) all works fine. Instead when I show android:src="@drawable/logo_big"
(it's just ONE png of 1417x1417pixel and 593KB in the drawable root folder) the image doesn't appear.
The layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageLogoBig"
android:layout_width="30dp"
android:layout_height="30dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo_big" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="@drawable/gplay_logo" />
</LinearLayout>
The imageLogoBig doesn't show in the upper example and in the lower example:
<ImageView
android:id="@+id/imageLogoBig"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo_big" />
I just discovered while I was writing the question that if I delete from drawable root directory the image logo_big and if I copy it in drawable-hdpi, drawable-ldpi, drawable-mdpi and drawable-xhdpi, all works fine. And this is strange because the other image: imageView1, is only in the drawable folder (but is 172x60px) and is showed correctly.
Why is this happening? Any suggest? (For example put logo_big only in drawable-xhdpi...)
Upvotes: 4
Views: 11112
Reputation: 4544
This can be for a number of reasons, one is the name of the file not being compliant, that's clearly not your case but I'm pretty sure it's of many others like me that would reach this question when looking for an answer.
In a nutshell, underscores '_' are permitted but hyphens '-' are not, maybe because these are used to add resource qualifiers to file names (or at least directories).
This is something easy to remember, but even easier to forget. So, to put an example, this file didn't work:
poa-sample.png
And the solution was to rename it to:
poa_sample.png
I leave this here JFTR, because as stupid as this is, it a made me waste a lot of time and try everything else before. You'd expect Android Studio to give an error at build time, as it would do with an invalid variable identifier for example, but as of today it won't give you even a proper warning.
Upvotes: 4
Reputation: 11
try renaming your image file to "logobig", without an underscore and see if that works. Even though file-based resource names allow underscores, i've had trouble occasionally
Upvotes: 0
Reputation: 1559
I solved moving logo_big
png image only to the directory drawable-xhdpi
, don't know really why, but it works now.
Upvotes: 9