ImageView displaying in layout but not on actual device
Solution 1
Alright I've tried changing the resolution of the image (cutting it in half making it 1000x130), and somehow that fixed the problem. I think Android can't render large images like that directly? I don't know, if you know more about the subject please don't hesitate to reply! Anyway, scaling down the image worked.
Solution 2
I had the same issue, it is only showing in Design tab for Android Studio 2.2.
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" />
Solution 3
For me, the problem was that I was using
tools:src=...
rather than
android:src=...
It got auto-generated trying to use an already existing template image.
Solution 4
you can use:
android:background="@drawable/home_bar"
instead of:
android:src="@drawable/home_bar"
Solution 5
I had the same issue and was able to solve it using following.
My problem was that the direction of the drawable archive was wrote in the second scrCompact
box.
I copy-pasted in the up box and the issue solved.
Related videos on Youtube
![Tim Kranen](https://i.stack.imgur.com/X7GcS.jpg?s=256&g=1)
Tim Kranen
Android Developer @ Little Labs Inc, Venice, California
Updated on September 22, 2021Comments
-
Tim Kranen almost 3 years
I have an ImageView that I want to display matching the full width of the device, I realized that like this:
<ImageView android:id="@+id/home_bar_newvault" android:layout_width="wrap_content" android:layout_height="40dp" android:scaleType="centerCrop" android:layout_alignParentBottom="true" android:src="@drawable/home_bar" />
The home_bar is a PNG image file with the following dimensions: 2399x254. When I choose to view the Graphical Layout of the UI it displays the imageview correctly at the bottom of the activity. However, when I start the application on my device it won't display the Imageview at all.
-
user2652394 almost 11 yearsDid you set the target screen and resolution of the
Graphical Layout
as same as your real device's? -
Tim Kranen almost 11 yearsYes, I've tried every resolution and target screen and they all display the ImageView in the Graphical Layout. I only have one physical device for the actual testing though, maybe a device related problem?
-
Josselin almost 7 yearsSee this answer. If the image is too large, the logcat will show a message like this one:
Bitmap too large to be uploaded into a texture (2496x4437, max=4096x4096)
-
-
Noah over 9 yearsRe-sizing the image worked for me as well. I had a 250x3000px image and I cut the image in half to 125x1500px and it appeared on the device.
-
Jayz7522 almost 7 yearsstackoverflow.com/questions/40624554/… Instead, you can easily add support for app:srcCompat
-
eric over 6 yearsIs there a way to get AS to stop doing that by default?
-
Wayneio almost 6 yearsFixed for me too. I've seen this before too, I keep forgetting it's an issue. There really needs to be an error message for this
-
Sunchezz about 5 yearsThe same thing still happened to me in Android Studio 3.4
-
Alexander Kiselev over 4 years"If you have a picture to use for everything not having a specific dpi, put it into res/drawable-nodpi" - It fine works for me! Thank you!
-
Rahee about 3 yearsWorked for me too. Thank you.
-
reza rahmad about 2 yearsyes it works in android studio april 2022 bumblebee