无法获取ListView背景渐变来显示

时间:2013-10-23 11:54:15

标签: android listview

我有一个listview,我希望有一个覆盖整个列表视图的背景渐变。我不想每行都有一个渐变。我得到的只是一个白色背景。

mybg.xml中的渐变代码:

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape>
      <gradient
        android:startColor="#e6e6e6"
        android:endColor="#ffffff"
        android:angle="45" />
    </shape>
  </item>
</selector>

我的ListView:

    <ListView
        android:id="@+id/lvEvents"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@drawable/mybg"
        android:cacheColorHint="#00000000"
        android:divider="#ffc0c0c0"
        android:dividerHeight="1dp"
        android:scrollingCache="true" />

2 个答案:

答案 0 :(得分:2)

尝试使用@null将行视图背景设置为透明。

答案 1 :(得分:1)

你错过了形状,试试这个

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="270"
        android:centerColor="#000000"
        android:endColor="#404040"
        android:startColor="#404040" />

</shape>