Android ListView : bad gradient divider

…衆ロ難τιáo~ 提交于 2019-12-11 14:23:20

问题


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.


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/20284131/android-listview-bad-gradient-divider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!