码迷,mamicode.com
首页 > 其他好文 > 详细

两种计算Text文本的尺寸的区别

时间:2017-08-15 22:54:05      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:***   int   tde   bsp   ttext   区别   测量   两种   selected   

(1)

通过getTextBounds的方式获取Text的绘制尺寸
/***
* 通过getTextBounds的方式获取Text的绘制尺寸
* @param text
* @return
*/
private int[] getTextMeasurementByBound(String text){
Rect textRect = new Rect();
Paint selectedItemPaint = new Paint();
selectedItemPaint.getTextBounds(text, 0, text.length(), textRect);
int measureHeight = textRect.height();
int measureWidth = textRect.width();
return new int[]{measureHeight, measureWidth};
}

(2)通过Layout测量的方式获取Text的绘制尺寸

/***
* 通过Layout测量的方式获取尺寸
* @param text
* @return
*/
private int getTextMeasurementByLayout(String text){
Rect textRect = new Rect();
Paint selectedItemPaint = new TextPaint();
int measureHeight = Layout.getDesiredWidth(text, selectedItemPaint);
return measureHeight;
}

 

两种计算Text文本的尺寸的区别

标签:***   int   tde   bsp   ttext   区别   测量   两种   selected   

原文地址:http://www.cnblogs.com/lzhen/p/7368027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!