3

I add the following code to main.xml to set an image as a background image for my app:

android:background="@drawable/bg"

So main.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom|fill_vertical"
android:background="@drawable/bg0"
>
<EditText
    android:id="@+id/edWord"
    android:layout_width="fill_parent"
    android:layout_height="53px"
    android:textSize="20px"
    android:singleLine="true"
    android:hint="" 
/>
<LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:layout_weight="1"
    >
    <ListView android:id="@+id/lstWord"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
    />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
>
    <ImageButton
        android:id="@+id/btnGetText"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/get"
        android:layout_weight="0.25"
    />
    <ImageButton
        android:id="@+id/btnFind"
        android:text="Click me..."
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/find"
        android:layout_weight="0.25"
    /> 

</LinearLayout>
</LinearLayout>

And of course the image bg.png is in drawable.

The problem is that the background image is shown only in the emulator but not in my actual device (HTC Desire).

What have I done wrong? What do I need to do to solve this problem?

Can you guys there help? Thank you very much.

Niamh Doyle
  • 1,909
  • 7
  • 30
  • 42

4 Answers4

1

try this in place of that

<LinearLayout 
    xmlns:android= "http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"            
        android:background="@drawable/bg" />
 </Linearlayout>
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
1

I found the problem . Just remove fill_parent from the main Linear Layout Gravity. No need to set background in the Listview as you do right now. Just Change as i suggest it solve your problem.

android:gravity="bottom|fill_vertical"
Chirag
  • 56,621
  • 29
  • 151
  • 198
0

I got a similar bug my background drawable was shown in the graphical editor of eclipse but not on the devices I used for debugging.

-> For me it helped to clean the image (I just opened it in paint and saved it) after that i overwrote the old image with the new one and copied it into the drawable folders.

Sebastian Walla
  • 1,104
  • 1
  • 9
  • 23
0

Some lolipop devices wouldn't show with higher resolution images. You could also manually resize the bitmap programmatically if you generate the backgrounds randomly or use a set of images to load them into the background

Akah
  • 1,389
  • 14
  • 19