0

I am trying to set a background image for my Main Activity. I have created different drawable folders such as drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxdpi, and drawable-xxxhdpi. I used Android asset studio to take one image and create a version of each image for each of the drawable folders.

Now when I try to add the background image in xml for the outermost layout like the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layoutContainer"
android:orientation="horizontal"
android:background="@drawable/ic_background">

A background image does get produced in the designer, however it does not cover the full screen. Here is a screenshot of how it looks like:

enter image description here

As you can see it doesn't cover the whole screen. What is the issue?

I just realized something. On Android asset studio there was an option for size. It was originally at 28 dp and I kept it there. Is that he reason why the image is not taking up the whole screen?

Edit

So I made the image size to the max possibility on Anroid asset Studio which is 200 dp. I also made padding set to 0. Now the image take the whole screen vertically. However horizontally the image does not take up the whole background.

Harshil.Chokshi
  • 671
  • 15
  • 26
  • what is the image size for each resolution ?check this link http://stackoverflow.com/questions/16135984/full-screen-background-image-in-an-activity – surya Sep 19 '16 at 17:46
  • 60x60 for hdpi, 40x40 for mdpi, 80x80 for xhdpi, 120x120 for xxhdpi, and 160x160 for xxxhdpi – Harshil.Chokshi Sep 19 '16 at 17:51
  • these resolution are not right see the correct sizes here you need to create different bitmaps for Landscape and portrait modes http://stackoverflow.com/questions/10574363/android-splash-screen-image-sizes-to-fit-all-devices/15744389#15744389 – surya Sep 19 '16 at 17:56
  • The answer is outdated. Can't I just use one drawable folder and place one high resolution image in it and android will scale down according to screen size? – Harshil.Chokshi Sep 19 '16 at 19:05
  • No android wont resize you need to give scale type to android in each case. Use a framelayout drawimageview first with sacletype and then you linearlayout – surya Sep 19 '16 at 23:12

2 Answers2

0

I think the resolution of your background image is not sufficient. Use a higher resolution picture and place it in /drawable-hdpi or /drawable-xhdpi folder (only at one place at a time). If this doesn't work out, try using relativelayout instead of linearlayout.

Tarun Khare
  • 1,447
  • 6
  • 25
  • 43
0

The picture you use as background has to have the PNG extension... If it does, just try to put your LinearLayout inside a RelativeLayout and add a background attribute to your LinearLayout with @android:color/transparent value And then, add your picture before your LinearLayout, inside your RelativeLayout, just like this :

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ...>
    <ImageView
        ... />
    <LinearLayout
        android:background="@android:color/transparent"
        ...>
    </LinearLayout>
</RelativeLayout>

Hope it will answer your question, Darkball60

Mesabloo
  • 337
  • 4
  • 13