Johann
Johann

Reputation: 29867

Can't get ListView background gradient to show

I have a listview and I want to have a background gradient that covers the entire listview. I don't want a gradient for each row. All I get is a white background.

Code for gradient in 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>

My 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" />

Upvotes: 1

Views: 489

Answers (2)

Alex
Alex

Reputation: 688

Try set the row view background to be transparent by using @null.

Upvotes: 2

Jitender Dev
Jitender Dev

Reputation: 6925

You missed the shape , try this

<?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>

Upvotes: 1

Related Questions