Android ListView滚动时背景样式问题

9

我需要对ListView进行样式设计,但是当滚动时它会变成黑色背景,我不知道为什么。我的ListView在LinearLayout中,而该布局的背景设置为图像。

这是我为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稳定时 - 我看到的背景与父布局中的应该一样。当我滚动时 - 我看到黑色背景,它正在擦除父布局的背景。如果我知道如何使用其他东西来设置它,那么这对我来说就没问题了。
3个回答

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>

0
在您的ListView的XML中尝试使用以下代码行:
android:listSelector="@android:color/transparent"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接