listView常用属性设置

  转 http://blog.csdn.net/tmj2014/article/details/7758787

  问题1:

listview在拖动的时候背景图片消失变成黑色背景。等到拖动完毕我们自己的背景图片才显示出来。

解决办法:

xml中: android:scrollingCache="false"  或者 android:cacheColorHint="#00000000"

代码中: setScrollingCacheEnabled(false)  或者 setCacheColorHint(0)  或者setCacheColorHint(Color.TRANSPARENT);

 

问题2:

listview的上边和下边有黑色的阴影。

解决办法:

xml中: android:fadingEdge="none"  

代码中:setFadingEdgeLength(0);

 

问题3:

lsitview的每一项之间需要设置一个图片做为间隔。

解决办法:

xml中 :android:divider="@drawable/list_driver

java中:Drawable dr = this.getResources().getDrawable(R.colo.listviewdividerClour);
              ListView.setDivider(dr);

 

问题4:

默认会显示选中的item为橙黄底色,有时候我们需要去掉这种效果:

解决办法:

xml中:listSelector="@android:color/transparent

衍生:

ListView选中时默认是黄色,很多时候会和我们软件的配色不符合,那么需要修改默认的ListView配色,

java中:

    1. Drawable drawable=getResources().getDrawable(R.drawable.touch_feedback);  
    2. ListView.setSelector(drawable); 

xml中:

listSelector="@android:color/blue

同理运用到 GridView中

原文地址:https://www.cnblogs.com/xingfuzzhd/p/2949425.html