2011-06-24 43 views
1

我在我的可繪製文件夾中有一個名爲bg.png的項目,但是它不會在我的列表視圖中顯示爲背景。我得到的只是默認的黑色。我究竟做錯了什麼?它需要是一個特定的大小,還是我的代碼中的問題?請參閱下面的main.xml:沒有出現在Android中的Listview背景

<LinearLayout android:id="@+id/LinearLayout01" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:background="@drawable/bg"> 

<ListView android:id="@+id/ListView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="#00000000" 
android:cacheColorHint="#00000000"> 

</ListView> 

</LinearLayout> 
+0

這看起來應該可以工作,但我的猜測是ListView有一個小錯誤或什麼的。一個listview可以是一個scrollview和一個佈局容器的組合......我很難過。 –

+0

我可以看到BG嗎?無論如何...這裏這段代碼沒有任何問題。你使用哪個SDK版本? – davidcesarino

+0

BG是一張364×648像素的羊皮紙(大小與它有什麼關係?),最小的SDK版本是8(2.2)。 – David

回答

0

好的,使用下面的代碼,它會工作。

<LinearLayout android:id="@+id/LinearLayout01" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"> 

<ListView android:id="@+id/ListView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/bg"> 

</ListView> 
</LinearLayout> 
0

在這裏的問題可能是你需要設置列表視圖項目這種顏色的背景色也是如此,因爲顯示的項目時,顯示的顏色列表視圖項的背景色不ListView控件本身。