代码之家  ›  专栏  ›  技术社区  ›  Sheehan Alam

每当我滚动时,ListView都会重新绘制背景色

  •  3
  • Sheehan Alam  · 技术社区  · 14 年前

    我已经定义了一个自定义的主题,我在我的窗口背景上画了一个深色渐变。我的ListView背景设置为透明,但是每当我滚动时,背景颜色变为黑色,然后滚动停止后,返回渐变色。为什么会这样?

    <?xml version="1.0" encoding="utf-8"?>
        <resources>
          <!-- Base application theme is the default theme. -->
          <style name="Theme" parent="android:Theme">
          </style>
    
          <!-- Variation on our application theme that has a translucent
         background. -->
          <style name="Theme.DarkGradient">
            <item name="android:windowBackground">@drawable/dark_gradient</item>
    
          </style>
    
        </resources>
    
    2 回复  |  直到 14 年前
        1
  •  11
  •   mreichelt    14 年前

    你的问题回答如下: http://developer.android.com/resources/articles/listview-backgrounds.html 你只需要设置 cacheColorHint 为了解决你的问题。:-)

        2
  •  1
  •   Pradeep    13 年前

    只需在xml listView中将cacheColorHint=“#00000000”设置为透明颜色

    <ListView android:id="@id/android:list" android:layout_width="320dp"
    android:layout_height="fill_parent" android:layout_centerHorizontal="true"
    android:divider="@color/whitetxtcolor"
    android:layout_weight="2" android:drawSelectorOnTop="false"     
    android:layout_below="@id/new_layout"
    android:cacheColorHint="#000000"
    ></ListView>
    

    或者你也可以这样做