把下面的XML文件保存成你自己命名的.xml文件(比如list_bg.xml),注意,这个文件相当于一个背景图片选择器,在系统使用时根据ListView中的列表项的状态来使用相应的背景图片,什么情况使用什么图片我在下面都进行了说明。还有,你可以把它看成是一个图片来使用,放于drawable目录下,配置背景属性android:background="@drawable/list_bg"就能达到你需要的目的了。
<
selector
xmlns:
android
=
"http://schemas.android.com/apk/res/android">
< item android :drawable= "@color/darkgray" android :state_pressed= "true"></ item>
< item android :drawable= "@color/gray_commnet"></ item>
</ selector>
< item android :drawable= "@color/darkgray" android :state_pressed= "true"></ item>
< item android :drawable= "@color/gray_commnet"></ item>
</ selector>
注意一定要用color 包下的颜色,否则不起作用,至今不是道为什么,就这么用吧
<?
xml version=
"1.0"
encoding=
"utf-8"
?>
< LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android :layout_width= "match_parent"
android :layout_height= "match_parent"
android :orientation= "vertical">
< LinearLayout
android :layout_width= "269dp"
android :layout_height= "wrap_content"
android :orientation= "vertical">
< TextView
android :background= "@drawable/list_item_color_bg"
android :id= "@+id/tv_review_comment"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
android :layout_below= "@id/iv_comment_head"
android :layout_toRightOf= "@id/iv_comment_head"
android :ellipsize= "none"
android :maxLines= "100"
android :scrollHorizontally= "false"
android :text= "一不下心就严把你放多少分放大师傅师傅说 方式发送方分公司放松放松放松发送方师傅师傅范德萨发生"
android :textColor= "#4a4a4a"
android :textSize= "13sp" />
</ LinearLayout>
</ LinearLayout>
< LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android :layout_width= "match_parent"
android :layout_height= "match_parent"
android :orientation= "vertical">
< LinearLayout
android :layout_width= "269dp"
android :layout_height= "wrap_content"
android :orientation= "vertical">
< TextView
android :background= "@drawable/list_item_color_bg"
android :id= "@+id/tv_review_comment"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
android :layout_below= "@id/iv_comment_head"
android :layout_toRightOf= "@id/iv_comment_head"
android :ellipsize= "none"
android :maxLines= "100"
android :scrollHorizontally= "false"
android :text= "一不下心就严把你放多少分放大师傅师傅说 方式发送方分公司放松放松放松发送方师傅师傅范德萨发生"
android :textColor= "#4a4a4a"
android :textSize= "13sp" />
</ LinearLayout>
</ LinearLayout>