2012-11-26 89 views
10

我目前有一個應用程序,每個幻燈片都有默認的黑色背景。我想要做的是改變XML文件以獲得背景圖像。我假設有一個簡單的命令,但一直沒能找到我正在尋找的東西。XML文件中的Android背景圖像

我想要一個圖像到我當前屏幕的背景。我不想讓背景變化,我想把它放在我的XML文件中。這裏是我的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:weightSum="1.0" > 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="9" 
    android:gravity="center" 
    > 

... 

我假設有一些簡單的命令,如

android:background="file" 
+0

詳細的博客:HTTP: //sforsuresh.in/set-background-image-android-xml/ –

回答

16

只需使用android:background="@drawable/file_name_without_extension"

如果你的文件是SD卡,你不能把它放在XML佈局。

5

您可以嘗試android:background = "@drawable/imagename"

我希望你在你的drawable文件夾

11

的Android有一個形象:背景= 「@繪製/ imagename」

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:background = "@drawable/imagename" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:weightSum="1.0" > 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="9" 
    android:gravity="center" 
    > 

...