1、首先建立两个样式文件,一个news_list_item_background.xml。内容如下:
一个 news_list_item_background1.xml
2、在listview对应的Adaptor类中的getView方法中增加如下代码:
if(position%2 == 0){ convertView.setBackgroundResource(R.layout.news_list_item_background); }else{ convertView.setBackgroundResource(R.layout.news_list_item_background1); }
其中关键是xml中的: