尝试在ListView的元素添加一些填充有android:padding="..."
,但如果你的名单列有不同的背景(或渐变背景)会有这些项目,并将列表边框之间的一些颜色差异。
或者,您可以尝试在第一个列表行的顶角和最后一个列表行的底角使用边界半径。在覆盖列表Adapter类的getView(...)
方法时,可以设置正确的背景可绘制xml资源。
Ex。 first_row_bg.xml的(对于第一行):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#b3b3b3"
android:endColor="#f5f5f5" />
<corners android:topLeftRadius="12dp"
android:topRightRadius="12dp"/>
</shape>
例last_row_bg.xml的(最后一排):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#b3b3b3"
android:endColor="#f5f5f5" />
<corners android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"/>
</shape>
例。 border_radius_bg.xml的(如果列表中只有一行):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#b3b3b3"
android:endColor="#f5f5f5" />
<corners android:radius="12dp"/>
</shape>
例。 gradient_bg.xml的(在中间行):getView(...)实现的
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#b3b3b3"
android:endColor="#f5f5f5" />
</shape>
例
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//inflate the layout (if necessary) and set the row content.
....
if(data.length==1) { // if we have only one row
convertView.setBackgroundResource(R.drawable.border_radius_bg);
} else if(position==0) { // first row
convertView.setBackgroundResource(R.drawable.first_row_bg);
} else if(position==data.length-1) { // last row
convertView.setBackgroundResource(R.drawable.last_row_bg);
} else { // row in the middle
convertView.setBackgroundResource(R.drawable.gradient_bg);
}
return convertView;
}
显然,.xml文件应保存在“可绘制”目录。
听起来像你的列表视图需要填充 – dhke 2015-03-30 18:52:40