【发布时间】:2013-11-24 05:36:25
【问题描述】:
我需要通过扩展 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);
}
}
【问题讨论】:
-
试图扩展 Drawable(并进行自定义 dtaw)而不是 ShapeDrawable?
标签: java android border drawable shapedrawable