获取文本的宽高

/**
     * 获取文本的高度
     * @param text
     * @return
     */
    private int getTextHeight(String text){
        Rect bounds = new Rect();
        mFanPaint.getTextBounds(text,0,text.length(),bounds);
        int height = bounds.bottom + bounds.height();
        return height;
    }

    /**
     * 获取文本的宽度
     * @param text
     * @return
     */
    private int getTextWidth(String text){
        Rect bounds = new Rect();
        mFanPaint.getTextBounds(text,0,text.length(),bounds);
        int width = bounds.left + bounds.width();
        return width;
    }

  

posted @ 2017-08-22 17:08  ha_cjy  阅读(335)  评论(0编辑  收藏  举报