android 画一对漂亮的括号。是()() 这种括号。注意是在canvas上画出来的 ,不是用字符代替的。
这是因为我需要根据需要不同尺寸的括号。但是用drawArc画出的括号很丑。以下是主要代码。如何才能画一个比较漂亮的括号呢。
public static final int bracketWidth = ViewTools.dip2px(7);
private static Paint bracketPaint = new Paint();
static {
bracketPaint.setStrokeWidth(ViewTools.dip2px(1.5f));
bracketPaint.setStyle(Paint.Style.STROKE );
}
public static void drawLeftBracket(Canvas canvas, int x, int y, int height) {
x += bracketWidth / 2;
RectF rect = new RectF(x, y, x + bracketWidth, y + height);
canvas.drawArc(rect, 90, 180, false, bracketPaint);
}
private static final int textBracketMaxHeight = ViewTools.dip2px(20);
private static final int textBracketMaxWidth = ViewTools.dip2px(10);
public static void drawLeftBracketPng(Canvas canvas, int x, int y,
int height){
Bitmap btp;
if (height > textBracketMaxHeight) {
btp = ViewTools.zoom(leftBracketPng, textBracketMaxWidth, height);
}else{
float scale = (float)height/leftBracketPng.getHeight();
btp = ViewTools.zoom(leftBracketPng, scale, scale);
}
canvas.drawBitmap(btp, x, y, new Paint());
}
public static void drawRightBracketPng(Canvas canvas, int x, int y,
int height){
Bitmap btp;
if (height > textBracketMaxHeight) {
btp = ViewTools.zoom(rightBracketPng, textBracketMaxWidth, height);
}else{
float scale = (float)height/rightBracketPng.getHeight();
btp = ViewTools.zoom(rightBracketPng, scale, scale);
}
canvas.drawBitmap(btp, x, y, new Paint());
}