这是我想要获得的(注意 - 蓝色只是hilited):
带有圆角的ListView和它的子元素,每个第n个具有白色浅灰色背景。
我有MyArrayAdapter
以不同的颜色绘制每一行:
public class AlternateRowArrayAdapter extends ArrayAdapter
{
private int[] colors;
public AlternateRowArrayAdapter(@NonNull Context context, @LayoutRes int layout,
@IdRes int textViewResourceId, @NonNull List<String> objects)
{
super(context, layout, textViewResourceId, objects);
colors = new int[] {ResourcesCompat.getColor(context.getResources(), R.color.white, null) ,
ResourcesCompat.getColor(context.getResources(), R.color.lmsLightGrey, null)};
}
/**
* Display rows in alternating colors
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
虽然ListView的子节点不尊重父节点的边界半径,但是将此背景颜色设置为它们的完整矩形:
我怎样才能告诉孩子们遵守父母的边界半径?