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.
Related
I am using android studio 2.3.3 , Jpg and webp images are showning on android studio layout editor but not showing when installed app on phone instead it is shown as empty white screen. PNG images are working fine. Whats the reason for this?
My layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/menu_categories"
android:scaleType="fitXY"
/>
</LinearLayout>
Layout inside Editor ScreenShot
Screenshot of device
Note that PNG images are working but i want to use jpg or webp images as they consume less space.
Thanks in advance
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 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
Hello I am trying to get Nine patch drawable from this tool Android Asset Studio, it generated the drawables of different density and that drawable I am setting as background of the button but drawables it generated has border line around images in four side that appear also when I am trying to run application in device.
Why it is so and can you please tell how this can avoided ?
<Button
android:id="#+id/submitButton"
android:layout_width="match_parent"
android:contentDescription="#null"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_views_vertical_top_margin"
android:background="#drawable/sign_up_via_email_selector" />
sign_up_via_email_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/sign_up_submit" />
</selector>
Thanks in advance
Check to see if the image has the correct name.
It should be sign_up_submit.9.png, the lines that appear are actually the areas that the 9patch defines for stretch.
If the image has the correct name it is a chance that the online utility application you used messed the resource. Try to use the 9patch generator from the android sdk(look for [your_sdk_path]\tools\draw9patch.bat), and try to generate one yourself and see if the problem is still there.
can you please check how you placed your 9 patch image in drawable folder,9 patch image should be named sign_up_submit.9.png
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);