2009-10-07 21 views
5

出於某種原因,每當我滾動瀏覽項目列表時,我的列表視圖中的背景消失並重新出現,導致我不想要的「閃爍」效果。我試過這個建議:How to make a ListView transparent in Android?,但由於某種原因它不起作用。有什麼建議麼?Android:ListView閃爍效果。有關如何擺脫這一點的任何提示?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/screenLayout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    > 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:background="@color/title_background" 
      android:text="@string/whatsnew_title" 
      > 
     </TextView> 
     <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      > 
     </ListView>  
</LinearLayout> 

回答

21

您是否包含android:cacheColorHint="#00000000"?這是建議的修復程序中最重要的部分。我剛剛試過你的代碼(顯然不是一個確切的複製品,因爲你正在使用對項目特定資源的引用),它似乎工作。

This post on the Android Developers blog應該是你的興趣。

+0

真棒...你不會相信我。 ..我試圖附加cacheColorHint,但我發現每一個資源說:android:cacheColorHint =「#000000」(注意零的數量顯然沒有說阿爾法)...現在它的作品完全按照我想要的...謝謝你很多! – Legend 2009-10-09 17:16:43

+0

偉大的答案男人。 – 2012-01-11 13:01:21

+0

偉大和簡短的迴應和少數!謝謝 – 2012-07-19 11:40:57

1

檢查您的theme.xml文件中的<item name="android:windowBackground">@null</item>。如果你有它 - 刪除它。我認爲其中一個受歡迎的資源就是以此爲例(這就是我得到的)。

+0

我實際上沒有自定義的theme.xml。你是否建議我創建一個? – Legend 2009-10-08 14:18:58

+0

你可以嘗試 - 我的喜好屏幕(這是ListView)有類似的問題,但是 - 我確實有自定義theme.xml和我的回答 – Bostone 2009-10-08 16:34:21

2

這也可以從Java(代碼)方面實現:listView.setCacheColorHint(Color.TRANSPARENT);