0

For few last days I'm trying to set background image in my android application. First I added my image to res/drawable-hdpi and set it as a background in .xml code of my activity by writing

<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/bground"
    tools:context="patrycja.MainActivity" >

It didn't work so I tried also to put this image into another drawable folder in res - without success. Then I even changed the extension of my file from .jpg to .png - nothing. So I got into res/values/styles.xml and added this:

 <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:background">@drawable/bground</item>
 </style>

Everytime my application compiles but when I try to start it I can't even go to my first activity because it stops. LogCat shows me RuntimeException, InvocationTargetException and OutOfMemoryError. Problem must be here because my app works good with setting colour as a background. Has anybody got an idea how to fix it?

6
  • whats the size and format of the image> Commented Nov 29, 2015 at 10:56
  • The size of an image is too high I guess. Commented Nov 29, 2015 at 11:00
  • It's 2395x3491 pixels. Is it too big? Commented Nov 29, 2015 at 11:03
  • @lawstud Yes of course. On which type of device you are targeting? Phone or tablet? What is the actual size of that image? Commented Nov 29, 2015 at 11:04
  • My target is Nexus One. I've changed size into 300x437 and it finally worked! Thank you very much :) Commented Nov 29, 2015 at 11:09

1 Answer 1

2

Try this:

  1. Use a .JPEG background.
  2. Keep it in res/drawable-nodpi directory.

I think this will work as I have faced a similar crash earlier.

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately it crashed again.
I think the resolution of the image is too high. I did this with 1280x720 image. No problem faced till now. Can you try with an image of lower resolution?
I resized it to 300x437 px and now it works. Thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.