My code run without any picture but when I add an image in background and run the app in my phone. The error says - the app has stopped.
My code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/apple_01">
My image's name is apple_01.
You may be getting a OutOfMemoryExeption try to lower the pixel size of the drawable, you can use photoshop or any other software to shrink the image size
You should try with another pic from file drawable such as
#drawable/abc_ab_share_pack_mtrl_alpha
if your app run correctly you should exchange the image
Related
I wanted a picture background. When I set the background property of the root element to the picture, it was distorted due to aspect ratio difference. After reading StackOverflow answers, I changed it to,
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/wallpaper1"/>
The image is a 300KB full HD image. It looks good, but the problem is that when I start the activity, there is a stutter and a warning message.
I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
When I removed the ImageView, there was no such problem. Should I not use 'src' in the layout XML, and load the image on my own using a background thread?
Try to convert image in to .webp format to reduce image size, and use lossless encoding type to keep image quality.
In Android Studio
1. right click on image asset
2. click Convert to WebP
3. Choose use lossless encoding and tap (API 18+)
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.
My application crashes when i put background line like in this code. When i delete this line my application works fine and also when i use another photo it also works. What's the problem?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/table2" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
The background for the main screen works fine also. But in the second page, it is problamatic.
If you are using only drawable folder to store all images.then change storage folder for high resolution images in drawable-xhdpi folder or higher.
Hope this helps.
Thanks to you all. I changed the dimensions from 2500x1900 to 1280x920, now it works.
Make sure about the image path if it is in drawable folder..put it inside Mipmap folder in your project directory.
I think you should check the size of your image anything above 300kb may tend to constantly crash your app. You can always use image compression Softwares to reduce the size of your image.
I want to display a png image on android. This is the image file:
The right end is a bit darker than left.
But the quality of image lost on android application(using ImageView):
Please note part in the red frame. The color is not changing smoothly.
But if I use the browser of my android phone, it plays good(so it's not reason of the phone screen):
This is my android code, which is pretty simple:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/hhh"/>
</LinearLayout>
where hhh is my first image posted here, which is under res/drawable.
I test it on my android phone(android 2.3.6) and android simulator(with android 2.2/2.3/4.0), all do not display good. But it plays good on my android pad(android 4.0.3).
What's the problem, and how to fix it?
Images in res/drawable are compressed. This is supposed to be lossless, but I've heard of similar issues in the past.
Move it into res/raw, and give it a go.
Try adding the following to your Activity and see if it helps.
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
//eliminates color banding
window.setFormat(PixelFormat.RGBA_8888);
}
This problem is a well-know it is a gradient banding issues, I have this problen and solve by add noise, such as http://planetphotoshop.com/say-goodbye-to-gradient-banding.html
I added some background pictures to different linear layouts in my application. as you can see on Eclipse they all look fine.The problem is that on an emulator or a phone the one for the main linear layout gets messed up, does anyone know why?
That's the code I used:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
>
The background is a real picture, not code:
The problem may be that your image is being read into a 16-bit (RGB565) bitmap. See http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/ -- you may want to read the image from /res/raw and use a BitmapFactory to read it in at the proper depth. Also see http://android.nakatome.net/2010/04/bitmap-basics.html for more on that. It also might be enough to make sure to save your .png with an alpha channel, which would force the system to interpret it as 32-bit.
Try this in Activity in onCreate() getWindow().setFormat(PixelFormat.RGBA_8888);