2012-11-21 21 views
3

我創建了一個特定的ListView,它存在於以下元素之外,用於創建一個滾動列表,每行包含一個左側的圖像和一些右側的文本。我是xml使用爲ListView是這樣的:Android背景ListView在滾動時變爲黑色

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#C8C8C8" 
> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawSelectorOnTop="false" 
    android:divider="#C8C8C8" 
    android:background="#C8C8C8"/> 

和ListView的行的XML代碼我使用下面給出:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="@drawable/bg_row" 
> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:paddingLeft="10px" 
     android:paddingRight="15px" 
     android:paddingTop="5px" 
     android:paddingBottom="5px" 
     android:layout_height="wrap_content" 
     android:src="@drawable/bg_image" 
    /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="5px" 
     android:paddingBottom="5px" 
     android:textSize="16sp" 
     android:textColor="#000000" 
     android:layout_gravity="center" 
     android:maxHeight="50px"/> 
</LinearLayout> 

只要是靜態所示的畫面(如在無運動)它會顯示正確,但是當我開始滾動瀏覽列出行項目的背景(可以在代碼中顯示的「圖標」)將被正確顯示,但「根」佈局的背景將變爲完全黑色......當滾動停止背景時,大多數的時候,找回它的顏色......當我測試的時候,我還在該元素中添加了一個具有相同背景的TextView,當列表滾動時,這個元素將會扣留它的顏色......任何想法爲什麼會發生這種情況,以及如何解決這個問題?

回答

0

上的ListView標籤

android:cacheColorHint="#00000000" // setting as a transparent color 
0

您需要將您的ListView的緩存顏色設置爲與您的ListView的顏色添加一個屬性:

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawSelectorOnTop="false" 
    android:divider="#C8C8C8" 
    android:background="#C8C8C8" 
    android:cacheColorHint="#C8C8C8" /> 

旁註:如果你希望你的分頻器是隱形,你也可以這樣做如下:

android:divider="@null"