嘗試在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