获取文本的宽高

Posted ha_cjy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取文本的宽高相关的知识,希望对你有一定的参考价值。

/**
     * 获取文本的高度
     * @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;
    }

  

以上是关于获取文本的宽高的主要内容,如果未能解决你的问题,请参考以下文章