ListView的孩子不尊重父母的边界半径

时间:2017-03-30 12:26:22

标签: android android-layout listview

这是我想要获得的(注意 - 蓝色只是hilited):
enter image description here
带有圆角的ListView和它的子元素,每个第n个具有白色浅灰色背景。

这是我在AS中的预览:
enter image description here

我有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的子节点不尊重父节点的边界半径,但是将此背景颜色设置为它们的完整矩形: enter image description here
我怎样才能告诉孩子们遵守父母的边界半径?

0 个答案:

没有答案