ImageView displaying in layout but not on actual device

别说谁变了你拦得住时间么 提交于 2019-11-28 22:40:06

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" />

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.

you can use:

android:background="@drawable/home_bar"

instead of:

android:src="@drawable/home_bar"

Use drawable-nodpi folder in res if image is too big.

Juan Francisco Romero Gutirrez

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.

I had a problem with a samsung phone not displaying my drawable but it worked fine on another phone. The picture was not in any large dimensions or otherwise abnormal.

To solve this I simply put my picture asset into a drawable subfolder instead of having it in the main drawable folder. E.g from res/drawable to res/drawable-mdpi worked for me. If you have a picture to use for everything not having a specific dpi, put it into res/drawable-nodpi. Here's a bit more about the dpi folders.

None of the above did the trick, it was a really big image, found this solution: In your manifest file

<application
        //this solve it for me.
        android:hardwareAccelerated="false"
        // Add this if the previuos line didn't solve tge problem
        android:largeHeap="true"
        android:theme="@style/AppTheme">

Solve it for me.

Hope it helps someone.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!