
android绘制圆角矩形为什么圆角边粗了
1个回答
2015-02-19 · 知道合伙人数码行家

知道合伙人数码行家
采纳数:117533
获赞数:517213
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注

展开全部
用shapedrawable画一个圆角矩形作为按钮的background,但是圆角的地方总是有点粗,和直接用xml做出来的背景不一样
float[]
outerR = new float[] { 20f, 20f, 20f, 20f, 0, 0, 0, 0 };
Shape shape = new
RoundRectShape(outerR, null, null);
image.setBackgroundDrawable(new
CustomShapeDrawable(shape,0xffea0000));
class CustomShapeDrawable extends
ShapeDrawable {
int color ;
public CustomShapeDrawable(Shape s,int
color) {
super(s);
this.color =
color;
}
@Override
protected void onDraw(Shape shape, Canvas
canvas, Paint paint) {
paint.setStrokeJoin(Join.ROUND);
paint.setDither(true);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setColor(0xffea0000);
paint.setStrokeWidth(4f);
shape.draw(canvas, paint);
}
}
把paint.setStrokeJoin这行去掉再试试
float[]
outerR = new float[] { 20f, 20f, 20f, 20f, 0, 0, 0, 0 };
Shape shape = new
RoundRectShape(outerR, null, null);
image.setBackgroundDrawable(new
CustomShapeDrawable(shape,0xffea0000));
class CustomShapeDrawable extends
ShapeDrawable {
int color ;
public CustomShapeDrawable(Shape s,int
color) {
super(s);
this.color =
color;
}
@Override
protected void onDraw(Shape shape, Canvas
canvas, Paint paint) {
paint.setStrokeJoin(Join.ROUND);
paint.setDither(true);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setColor(0xffea0000);
paint.setStrokeWidth(4f);
shape.draw(canvas, paint);
}
}
把paint.setStrokeJoin这行去掉再试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询