【发布时间】:2012-03-09 11:11:07
【问题描述】:
我将以下代码添加到 main.xml 以将图像设置为我的应用的背景图像:
android:background="@drawable/bg"
所以main.xml 看起来像这样:
<?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>
当然,bg.png 的图像在 drawable 中。
问题是背景图像仅显示在模拟器中,而不显示在我的实际设备(HTC Desire)中。
我做错了什么?我需要做些什么来解决这个问题?
你们能帮忙吗?非常感谢。
【问题讨论】:
-
你能发布完整的xml文件吗?
-
非常感谢,尤其是@NagarjunaReddy。最后,我自己解决问题如下:
<ListView android:id="@+id/lstWord" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg0" /> ...
标签: android image listview background