Domanda

I have a ListView :

<ListView
    android:id="@+id/mainList"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="1dip"
    android:layout_marginRight="1dip"
    android:divider="@drawable/list_divider"
    android:dividerHeight="1px"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:cacheColorHint="#00000000"
/>

and a shape in list_divider.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
   <gradient
      android:startColor="#00000000"
      android:centerColor="#FFFFFFFF"
      android:endColor="#00000000"
      android:angle="0" />
</shape>

but instead of having a divider like this : white - gray - black - gray - white
I get this : white - gray - black - gray - white - gray - black - gray - white ???
In short the divider is splitted into two similar parts and I need only one.

È stato utile?

Soluzione

For gradient white-gray-black-gray-white use :

<gradient
   android:startColor="#ffffff"
   android:centerColor="#000000"
   android:endColor="#ffffff"
   android:angle="0">

Double gradient is probably due to Alpha channel you added to your colors. Center color, for example, starts with #00 (8 bytes) and means full transparent so you have the under layer color.

Altri suggerimenti

I have changed the gradient a little bit. Might be useful for some.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <gradient
      android:startColor="#E4E4E4"
      android:centerColor="#F0F0F0"
      android:endColor="#E4E4E4"
      android:angle="90" />
</shape>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top