計(jì)算指定參數(shù)長(zhǎng)度能顯示多少個(gè)字符礁扮,同時(shí)可以獲取指定參數(shù)下可顯示字符的真實(shí)長(zhǎng)度知举,譬如:
private static final String STR = "你好!世界";
mPaint.setTextSize(50);
float[] value = new float[1];
int ret = mPaint.breakText(STR, true, 200, value);
Log.i("YYYY", "breakText="+ret+", STR="+STR.length()+", value="+value[1]);
//breakText=5, STR=8, value=195.0
void getTextBounds(char[] text, int index, int count, Rect bounds)
void getTextBounds(String text, int start, int end, Rect bounds)
獲取文本的寬高太伊,通過bounds的Rect拿到整型负蠕。
float measureText(String text)
float measureText(CharSequence text, int start, int end)
float measureText(String text, int start, int end)
float measureText(char[] text, int index, int count)
粗略獲取文本的寬度,和上面的getTextBounds比較類似倦畅,返回浮點(diǎn)數(shù)遮糖。
int getTextWidths(String text, int start, int end, float[] widths)
int getTextWidths(String text, float[] widths)
int getTextWidths(CharSequence text, int start, int end, float[] widths)
int getTextWidths(char[] text, int index, int count, float[] widths)
精確計(jì)算文字寬度,與上面兩個(gè)類似叠赐。