Android自定义View之getTextBounds()

在Android自定义View的过程中一定会用到Paint,而paint属性中有一个方法getTextBounds(String text,int start,int end,Rext bounds),它的中文解释是:返回一个包含中文的矩形边界,位置为(start,end)

英文解释:Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).由调用者返回在边界(分配)的最小矩形包含所有的字符,以隐含原点(0,0)。

Parameters

text    String:String to measure and return its bounds  要测量的字符串,并返回它的界限

start   int:Index of the first char in the string to measure  在这个字符串里的第一个字符的索引,它将作为测量的起点

end    int:1 past the last char in the string  measure

bounds    Rect:Returns the unioned bounds of all the text.返回包含文本在内,所形成的边界。

下面是第二个方法:

void getTextBounds (char[] text, 
                int index, 
                int count, 
                Rect bounds)
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).由调用者返回在边界(分配)的最小矩形包含所有的字符,以隐含原点(0,0)。


Parameters
text    char: Array of chars to measure and return their unioned bounds一个包含字符的数组,测量并返回他们的联合边界
index    int: Index of the first char in the array to measure 在这个 数组 里的第一个(要测量的)字符的索引(你不一定要指定为0, 虽然那确实意味着从第一个开始),它将作为测量的起点
count    int: The number of chars, beginning at index, to measure字符的数量(比如5),测量将会 开始于上面指定的索引号,结束于 此数量值之后(若为5, 则上面指定的索引号+5)
bounds    Rect: Returns the unioned bounds of all the text. Must be allocated by the caller.返回包含所有文本在内,所形成的边界,(所以叫unioned bounds)。必须分配给调用者。


 

猜你喜欢

转载自blog.csdn.net/weixin_38664232/article/details/84846281