解决ListView的listSelector被覆盖不起作用的问题

ListView的listSelector属性可以为列表的某个元素被点击时产生按下的效果,但是某些情况下这个listSelector属性的效果会被覆盖,比如列表的Item为一个占满单元格的ImageView的时候,ImageView如果有内容那么listSelector的效果就会被挡住。

解决的办法是为ListView添加drawSelectorOnTop属性并设置为true。

drawSelectorOnTop的解释:

When set to true, the selector will be drawn over the selecteditem. Otherwise the selector is drawn behind the selected item. Thedefault value is false.

当设置为true,selector 将绘制在被点击item的上面,反之绘制在被点击item的下面,默认为false。

android:drawSelectorOnTop="true" 点击某一条记录,颜色会显示在最上面,记录上的文字被遮住,所以点击文字不放,文字就看不到

android:drawSelectorOnTop="false"点击某条记录不放,颜色会在记录的后面,成为背景色,但是记录内容的文字是可见的