美文网首页
计算文本宽度和高度

计算文本宽度和高度

作者: 梦沉薇露 | 来源:发表于2017-04-24 14:54 被阅读37次
/** 
     * 计算文本高度 
     */  
    public int getTextHeight(Paint paint){  
        Paint.FontMetrics fm = paint.getFontMetrics();  
        return (int)(Math.abs(fm.ascent) + Math.abs(fm.descent));  
    }  
  
    /** 
     * 计算文本宽度 
     */  
    public int getTextWidth(TextPaint paint ,String str){  
        int x = (int)paint.measureText(str);  
        return x;  
    }  

相关文章

网友评论

      本文标题:计算文本宽度和高度

      本文链接:https://www.haomeiwen.com/subject/hblpzttx.html