2

I'm learning Android programming, and am having a problem when I want to add a Background Image to an Activity that says hello android (The default app when we create a project). I tried with way smaller images and it worked, but I want to use a big image, and when I use that big image, it doesn't work on my device, which is Samsung Galaxy Grand Duos.

I'm using the android:background="@drawable/my_big_image" inside the activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:background="@drawable/a_real_big_image"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
    />
</RelativeLayout>

The image is png, and its dimensions are 1688x1464. I put that image in every single folder that says drawable.

Do you know how to solve this error?

Thanks in advance.

Melquiades
  • 8,496
  • 1
  • 31
  • 46
  • 1
    Each image is about 9.8MB! You didn't say what "doesn't work means", but I'm guessing out of memory. – Simon Jan 25 '14 at 17:41
  • possible duplicate of [Strange out of memory issue while loading an image to a Bitmap object](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – Simon Jan 25 '14 at 17:42
  • @Simon correct - bitmaps occupy a lot of memory: 1688X1494 * 4 = 9.9 MB. I suggest user3220206 to study this link: http://developer.android.com/training/displaying-bitmaps/index.html – Björn Hallström Jan 25 '14 at 18:08
  • It doesnt show up, like if i didnt put a background image. – Joel Alvarez Myrrie Jan 25 '14 at 18:18

1 Answers1

0

Try resizing the image using paint or other software to somewhere around 400px width and try if the image then shows up.

Also try cleaning and building your project again.

klifa
  • 671
  • 1
  • 8
  • 27