CardView代码中设置圆角会被设置背景覆盖,以下代码运行后cardview圆角无效:
card.setBackgroundResource(R.id.image);
card.setRadius(50);
应改成:
//card.setBackgroundResource(R.id.image);
card.setRadius(50);
ImageView img = new ImageView(getContext());
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
img.setLayoutParams(params1);
img.setBackgroundResource(R.id.image);
card.addView(img);