开发者社区> 问答> 正文

android 怎样画一对漂亮的括号

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);
    }

展开
收起
蛮大人123 2016-06-03 10:43:34 2232 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    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());
        }
    2019-07-17 19:26:13
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载