如何将背景图像添加到Android Activity?

mar*_*les 21 android

我的目标是在背景图像上开发GUI应用程序,在图像上的特定位置使用按钮.第一步是显示背景.

图像可以显示资源,并在几个常见问题解答中描述,包括这一个:

如何到添加背景图像对活动

它编译并运行没有错误,但背景是黑色的.

这是main.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/rootRL" 
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@drawable/background">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

图像采用png,9.png和jpg格式,基本名称为"main"和"background".它构建但不显示.清理和重新编译没有帮助.

在仿真器和硬件上都会出现此问题 - Atmel AT91SAM9M10-G45-EK.SDK版本是2.0.1.

谢谢您的帮助.

mar*_*les 5

问题解决了:代码基于具有文本视图并动态设置窗口的代码.

Hello Android示例会调用setContentView(R.layout.main)哪个是我需要的线索.

当然定义了背景,res/layout/main.xml所以有必要调用setContentView(R.layout.main)来获取这些设置.