Today I received a complaint for an app that I made. Basically, the problem is that I have an ImageView which loads an image from the resources directory, but sometimes, the image is not loaded and a white space is displayed instead. The only complaint comes from Sony Xperia Z3 with the Android version 5.1.1. The drawable is added only for xhdpi, but I know that if needed Android scales it to the corresponding resolution. Do you have any ideas why this could take place since I wasn't able to reproduce the bug? Also, here's my ImageView code but I'm sure that there is no problem.
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="#dimen/padding_medium"
android:background="#drawable/green_logo"
android:scaleType="fitCenter"
android:contentDescription="#null" />
Why do you use background for ImageView? Use android:src="#drawable/image".
Related
I have this weird issue. Samsung Note3 is not displaying background image of one of my activities:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/fullscreen_bg"
tools:context="com.myapp.views.activities.LoginActivity">
</RelativeLayout>
fullscreen_bg image is present in each drawable folder. Every emulator I've run my app on was displaying this image correctly but on this phone model it's not. Any advice?
What is the resolution of your image?
I think is because the resolution of the image. Try to scale down the image to the half just to do a test.
Also if you are using different drawable-XXX, try to use only "drawable" without sufixes.
I am using Android Studio version 2.2. I am facing strange thing first time. In one of my layouts I am using image ‘abc.png’ and Android Studio preview showing the right preview with right image, but on real device the image is different. The real device getting image wrong constantly. I don’ know what am I doing wrong? Below is the button code.
<Button
android:id="#+id/btn_pay"
android:textColor="#525252"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="30dp"
android:background="#drawable/btn_normal"
android:text="Pay" />
Android studio is showing this preview as expected because 'Button image' (text 'Pay' is placed) I am using is what it should be.
but on real device it is showing different image as shown below
The button is getting wrong image on real device. One more thing I have checked some this button with other colored images as background it is properly reflected on android studio preview but on real device it always shows the same image no matter what image I use on background. Any help?
After struggling a lot, I have found the problem. The problem was not with Button png or xml drawable. The problem was in java coding. The image was placed programmatically. I have posted the answer in case it may help full for others.
I'm currently working on a Navigation Drawer where I want the user photo to be scaled, cropped, tinted, then used as the header image behind a circular crop of there picture.
I can't even post images because this account is too low rep...damn me and using my old student account for most of my questions...
Despite my ImageView being defined like this
<ImageView
android:tint="#color/clyp_copy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pixplogo"
android:scaleType="centerCrop"
android:adjustViewBounds="true"/>
This image (1) skews like this (2) (Same link, two images)
This is actually a common issue for me. I've never gotten centerCrop to work properly. I don't understand why.
Testing on 5.1.1, building on SDK 23. Same issue on 21
Not sure if this is allowed on SO, but here's a Debug apk...maybe it's just my device...or 5.x
Replace
android:background="#drawable/pixplogo"
with
android:src="#drawable/pixplogo"
Creating vector images in Photoshop (for transparent backgrounds). When I add them as the image source for my ImageButtons, and run the app, the image displays with a white background.
Can't find any useful info on why the images are not coming out transparent through the app.
Are there some additional steps/coding required to make vector images work properly? I can't see why.
Example code, as requested:
<ImageButton
android:id="#+id/btnGameUp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/arrowright"
android:adjustViewBounds="false"
android:clickable="true"
android:cropToPadding="false"
android:padding="0dp"
android:scaleType="fitXY"
android:layout_marginLeft="270dp"
android:layout_marginTop="260dp" />
No one came to help us, but we managed to find the solution on our own after hours of crying and holding each other for comfort.
In the layout xml file, you need to add the following line to each vector object:
android:background="#android:color/transparent"
That's it! Tested and working perfectly. Hope this helps someone.
When trying to add a custom image to a ImageButton, I get the following error:
E/AndroidRuntime(3304): Caused by: java.io.FileNotFoundException: res/drawable/btn_default.xml
This Works:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/btn_plus" />
This does not:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/elec" />
On the designer I can see the image fine on the button, but as soon as I try to run it, I get the above error. The elec.png file is in drawable-hdpi.
Burned 3 hours trying to find the problem. Any help really appreciated!
You should also put you image in the drawable folder ( + correctly sized version in drawable-ldpi, drawable-mdpi, drawable-xhdpi to follow Android guidelines )
In the end, it turned out that my emulator was somehow corrupted. The code works perfectly on a real device and on a newly generated emulator.