lawstud
lawstud

Reputation: 185

Setting background image in android application

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?

Upvotes: 0

Views: 1930

Answers (1)

Embydextrous
Embydextrous

Reputation: 1661

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.

Upvotes: 2

Related Questions