【问题标题】:Android ListView style issue with background while scroll滚动时背景的Android ListView样式问题
【发布时间】:2011-05-24 18:59:23
【问题描述】:

我需要设置 ListView 的样式,但不知道为什么滚动时它会变成黑色背景。我在 LinearLayout 中有 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 稳定时 - 我看到背景应该来自父布局。当我滚动时 - 我看到黑色背景,它正在擦除父母的背景。如果我知道如何用其他东西设置它,我会很好的..

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    在listView的xml中使用如下属性:

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

    【讨论】:

      【解决方案2】:

      在列表视图的 xml 中尝试这行代码:

      android:listSelector="@android:color/transparent"

      【讨论】:

        【解决方案3】:

        如果您需要在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>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-22
          • 1970-01-01
          • 2011-02-19
          • 2012-11-20
          • 2011-03-07
          • 1970-01-01
          相关资源
          最近更新 更多