如何将背景图片添加到Android活动?
问题描述:
我的目标是在背景图像上使用图像上特定位置的按钮开发GUI应用程序。第一步是显示背景。如何将背景图片添加到Android活动?
的图像可以被显示的资源和在几种常见问题包括这一个描述:
how-to-add-background-image-to-activity
它编译和没有错误运行,但背景是黑色的。
下面是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>
的形象一直在PNG,9.png和JPG格式的 '主' 和 '背景' 基本名称。它构建,但不显示。清理并重新编译并没有帮助。
在模拟器和硬件上 - Atmel AT91SAM9M10-G45-EK上都会出现这种情况。 SDK版本是2.0.1。
谢谢你的帮助。
答
问题解决:代码基于具有文本视图并动态设置窗口的代码。
Hello Android示例的确称为setContentView(R.layout.main)
,这是我需要的线索。
当然在res/layout/main.xml
定义的背景,所以有必要拨打setContentView(R.layout.main)
来获得这些设置。
如何添加代码? – baash05 2012-02-16 12:02:47
重复:如何添加您的代码? – 2015-01-11 21:21:27