【发布时间】:2019-04-28 07:39:52
【问题描述】:
【问题讨论】:
-
我的关键字是:自定义可绘制形状android
-
请检查我更新的答案,如果有帮助,请告诉我。 :)
标签: java android android-custom-view android-drawable
【问题讨论】:
标签: java android android-custom-view android-drawable
要以编程方式实现圆形可绘制,您需要具有如下功能。
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;
}
并在您的ImageView 中设置drawable,如下所示。
imageView.setBackground(drawCircle(getResources().getColor(android.R.color.holo_blue_dark), getResources().getColor(android.R.color.holo_red_dark)));
这是给这样的东西。
【讨论】: