Android background image not shown in device?
10,029
Solution 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"
Solution 2
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>
Author by
Niamh Doyle
Updated on June 04, 2022Comments
-
Niamh Doyle almost 2 years
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 indrawable
.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.