要以编程方式实现圆形绘制,您需要具有如下函数。
public static GradientDrawable drawCircle(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.OVAL);
shape.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(10, borderColor);
return shape;
}
并在你的drawable
中设置ImageView
,如下所示。
imageView.setBackground(drawCircle(getResources().getColor(android.R.color.holo_blue_dark), getResources().getColor(android.R.color.holo_red_dark)));
这是给这样的东西。