我需要通过扩展ShapeDrawable以编程方式创建带圆角的边框。我需要有一个圆角黑色边框,外侧像素为白色,内侧像素为透明。我目前的代码有多个问题,其中包括它不会创建与边框厚度相同的光滑角,并且边框的外部像素是透明的而不是白色的。如何以编程方式在Android中使用ShapeDrawable创建圆角边框?
这里是弯道我目前得到
这里是哪里,我在构造函数传递Color.TRANSPARENT为“补”的代码的图片:
public class CustomShape extends ShapeDrawable {
private final Paint fillpaint, strokepaint;
public CustomShape(int fill, int strokeWidth,int radius) {
super(new RoundRectShape(new float[] { radius, radius, radius, radius, radius, radius, radius, radius }, null, null));
fillpaint = new Paint(this.getPaint());
fillpaint.setColor(fill);
strokepaint = new Paint(fillpaint);
strokepaint.setStyle(Paint.Style.STROKE);
strokepaint.setStrokeWidth(strokeWidth);
strokepaint.setColor(Color.BLACK);
}
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
shape.draw(canvas, fillpaint);
shape.draw(canvas, strokepaint);
}
}
+0
试图扩大可绘制(并做一个自定义dtaw)而不是ShapeDrawable? –