ImageView displaying in layout but not on actual device

68,794

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.

enter image description here

Share:
68,794

Related videos on Youtube

Tim Kranen
Author by

Tim Kranen

Android Developer @ Little Labs Inc, Venice, California

Updated on September 22, 2021

Comments

  • Tim Kranen
    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
      user2652394 almost 11 years
      Did you set the target screen and resolution of the Graphical Layout as same as your real device's?
    • Tim Kranen
      Tim Kranen almost 11 years
      Yes, 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
      Josselin almost 7 years
      See 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
    Noah over 9 years
    Re-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
    Jayz7522 almost 7 years
    stackoverflow.com/questions/40624554/… Instead, you can easily add support for app:srcCompat
  • eric
    eric over 6 years
    Is there a way to get AS to stop doing that by default?
  • Wayneio
    Wayneio almost 6 years
    Fixed 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
    Sunchezz about 5 years
    The same thing still happened to me in Android Studio 3.4
  • Alexander Kiselev
    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
    Rahee about 3 years
    Worked for me too. Thank you.
  • reza rahmad
    reza rahmad about 2 years
    yes it works in android studio april 2022 bumblebee