(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;}
时间: 2024-12-18 11:20:00