Reputation: 577
Can anyone tell me why the following code is not working? The Image does not appear at all.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<ImageView
android:src="@drawable/splashscreen"
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Upvotes: 39
Views: 113004
Reputation: 2731
None of these work for Android WearOS
You need to use android:src="@drawable/ic_check"
inside your ImageView
for it to appear.
app:srcCompat
and android:srcCompat
do not work.
Upvotes: 0
Reputation: 514
in my case replacing tools:srcCompat
with android:srcCompat
in the xml tag of the image view solved the problem
Upvotes: 0
Reputation: 1
if your Image is not displaying in your code because of some layout errors you can usetools:ignore="contentDescription"
usetools:ignore="contentDescription"
use this line in code.
Upvotes: -1
Reputation: 541
100% working code . same problem show in my code . but i am using AppCompatImageView after then show my image
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/ic_calendar"
/>
Upvotes: 3
Reputation: 61
Try to use app:srcCompat="@drawable/modified"
instead of tools:srcCompat="@drawable/modified"
in XML files.
Upvotes: 6
Reputation:
My issue was that the layout alpha was set to 0 which is what went wrong. Sometimes alpha comes by itself. Anyway 0 alpha is the default value even if not mentioned. So try to remove alpha as 0. 0 alpha is = invisible!!
Upvotes: 0
Reputation: 53
Try Changing from ImageView
to androidx.appcompat.widget.AppCompatImageView
in your layout file
Upvotes: 1
Reputation: 21
Try adding this line in ImageView XML file
android:src="@drawable/splashscreen"
tools:srcCompat="@drawable/splashscreen"
Upvotes: 0
Reputation: 1388
Not related to this question but still sharing an experience, sometimes we set the source to the tools and then we expect a result (happened to me twice and took 15 minutes each time to resolve).
tools:srcCompat
//instead of
android:srcCompat
Image source for tools is visible in android studio only.
Upvotes: 2
Reputation: 3469
Look in your logcat output as well. You may see an image similar to this one:
OpenGLRenderer 0x0000644a:0 Bitmap too large to be uploaded into a texture (4203x2277, max=4096x4096)
If this is the case, decrease the image size.
Upvotes: 0
Reputation: 61
If you are new to Android Development like I am, READ THESE DOCS:
Android Official Documentation
Medium Article from a LinkedIn Android Dev
I've done iOS development for several years now and decided to branch out into Android development. I found that most of the time it is entirely to do with screen resolution (also mipmap is NOT for drawable images as mentioned before).
None of these answers fixed my issues, I had to setup the standard resolution directories of drawable-hdpi
, drawable-mdpi
, drawable-xhdpi
, drawable-xxhdpi
, and drawable-xxxhdpi
. These are all of the directories your emulator or devices will look at when searching for the correct resolution for the device setup. If you put your image in drawable
alone, this could cause these folders to be overlooked by the device and that's when you get a high-resolution image being non-visible or crashing the app from memory errors. Be sure to check the dimensions of your image and make sure that you import it under the correct drawable directories to ensure the device scales the image accordingly.
My explanation is a small overview, but I do highly recommend reading the articles.
Upvotes: 0
Reputation: 1086
In ImageView there is two options src and srcCompact. Try both of them to find out which is working.
android:src="@drawable/slide_view_4"
and
app:srcCompat="@drawable/slide_view_4"
Upvotes: 44
Reputation: 994
Android ImageView Is Not Displaying Image?
none of these solutions are not worked for me. what i did was i added these code lines in my manifest file
android:hardwareAccelerated="false"
android:largeHeap="true"
if these codes line didn't solve your problem try to set your image view height and width. not using wrap content or match parent. if your size didn't worked. try to reduce the number and retry. i think these solutions are helpful.
Upvotes: 2
Reputation: 1758
Try android:background="@drawable/your_image"
instead of app:srcCompat="@drawable/your_image"
Upvotes: 4
Reputation: 325
I was facing the same issue. After a bit of work I found out that if I placed the image in the drawable(anydpi), which was being rendered in the design preview but not on the real device it was a problem. So, I placed the image inside simple drawable folder rather than drawable(anydpi). That fixed my issue.
Upvotes: 0
Reputation: 15
I was facing the exact same problem. I tried rebuild but it did not help. Finally I resized the image from its original size of 2400x2400 to 1200x1200 using an online PNG resizer and then compressed it from 590KB to 150KB file size using an online compressor.
Upvotes: 1
Reputation: 105
Image file name matters as well. Make sure when you name your image, there are no spaces. Use "_" instead or something
Upvotes: 0
Reputation: 3
I copied/pasted a PNG image into the Drawable folder and set all the info and params in XML file
---> image showed in the Preview but not on actually device/emulator.
So--> In Java Activity, I recalled it programmatically:
ImageView imview = (ImageView) findViewById(R.id.IdFromXML);
imview.setImageResource(0);
Drawable draw = getResources().getDrawable(R.drawable.NameOfTheFileInFolder);
draw = (draw);
imview.setImageDrawable(draw);
Got it done!
Convert Image to PNG if necessary. Plenty free converters online.
Upvotes: 0
Reputation: 11
Try to check the name of your image eg:"img-icon-butterfly.png" these type of names should be renamed and "-" should be removed so instead use names like "imgbutterfly.png"
Upvotes: 1
Reputation: 614
I had the same issue and I fixed it by extending AppCompatActivity
and renaming my image to correct standard.
My image name (previously): splash-1 (didn't worked).
And I tried renaming image name to splash1.
After that everything worked.
note: the image file might also be responsible for this problem.
Upvotes: 7
Reputation: 359
try making the image size a little less, I guess the android studio doesn't support the image with higher pixels .Anyway it solved my problem
Upvotes: 0
Reputation: 2046
Please check your image color...If you are using the white background and if you use the white color image then it will not be displayed...Try changing your background container for the image to some other color or change your image color. I really faced this situation and wasted lot of time...I hope this will help someone...
Upvotes: 1
Reputation: 29
I had this same problem. I really cannot believe how simple it was. Though this may not be the issue for you, this fixed it for me. My image file was named ss-logo.png. Android Studio does not allow dashes in image files. Once I changed it to ss_logo.png, it worked perfectly. Only use letters, numbers, and underscores in your image file name. Hope this helps.
Upvotes: 1
Reputation: 609
In my case, the image wasn't visible while choosing the image from the list of images.
Rebuilding the project fixed it for me.
Build -> Rebuild Project
Upvotes: 1
Reputation: 2375
Don't create drawable folder yourself. Recreate it with Image Asset option in android studio.
In my case, the problem was drawable folder itself. i had created drawable folder myself. it's not correct. in the android studio we should create drawable folder with Image Asset option. i didn't get the reason but now the problem is sloved.
Upvotes: 0
Reputation: 359
In my case, all my fragment's imageViews are not showing when I run my application. The problem is, I extend my "Activity" class from "FragmentActivity". so I just change it "FragmentActivity" to "AppCompatActivity"
maybe this will help someone.
Upvotes: 35
Reputation: 81
This is the solution that worked for me after checking the layout xml, theme etc. Just changing the "extends Activity" from your java class to "extends AppCompatActivity".
Should some of the previous suggested solutions worked for you, others having the same problem with ImageView image not showing might try this as well.
Upvotes: 8
Reputation: 3361
Where did you put the source image file? Is that under the Drawable folder? If so, then create mdpi, hdpi, xhdpi, xxhdpi image source for the image, and put them in mdpi, hdpi, xhdpi, xxhdpi folders.
Upvotes: 10
Reputation: 5004
Many of the image related issues are solved by using the third party libraries like Picasso by Jake Wharton. I had unexplained issues with image loading and some times even getting out of memory error. That was especially cased by imaged edited (using Gimp for Mac). Picasso does the hard work of handling the memory and necessary caching etc.
http://square.github.io/picasso/
Upvotes: -1
Reputation: 130
Check for the following:
setContentView
(for your splash screen) on the UI threadsetContentView
)?ImageView
layout_height
and layout_width
.Upvotes: 3