标签:*** 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;
}
标签:*** int tde bsp ttext 区别 测量 两种 selected
原文地址:http://www.cnblogs.com/lzhen/p/7368027.html