2011-05-24 52 views
9

我需要風格的ListView,並不能弄清楚爲什麼它會變成黑色背景時滾動..我有ListView內LinearLayout和該佈局已將背景設置爲圖像。Android ListView風格與滾動背景的問題

這是我有ListView控件:

<style name="MyListView" parent="@android:style/Widget.ListView"> 
     <item name="android:listSelector">@drawable/selector_list_item</item> 
    </style> 

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false" android:state_focused="true" 
      android:drawable="@drawable/shape_list_item_normal" /> 
    <item android:state_pressed="true" 
      android:drawable="@drawable/shape_list_item_pressed" /> 
    <item android:state_focused="true" 
      android:drawable="@drawable/shape_list_item_normal" /> 
</selector> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <gradient android:startColor="#80ffffff" android:endColor="#80eff3ef" android:angle="45" /> 
    <padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/> 
</shape> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <gradient android:startColor="#80808080" android:endColor="#80eff3ef" android:angle="45" /> 
    <padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/> 
</shape> 

當我申請MyListView風格我看不出有發生。當我點擊項目 - 是的,我看到漸變。當ListView穩定 - 我看到背景,因爲它應該從父佈局。當我滾動時 - 我看到黑色背景,這是擦除父母的背景。我將罰款,如果我知道如何去用別的東西把它..

回答

0

試試這行代碼在你的列表視圖的XML:

機器人:listSelector =「@安卓:彩色/透明「

8

使用以下屬性ListView中的XML:

android:cacheColorHint="@android:color/transparent" 
0

如果您在PreferenceActivity需要透明ListView,請嘗試使用主題與

<resources> 

    <style name="MyPreferencesTheme"> 
     <item name="android:scrollingCache">false</item> 
    </style> 

</resources> 

並把主題在你的AndroidManifest.xml

<activity 
    android:name="YourActivity" 
    android:theme="@style/MyPreferencesTheme"> 
</activity>