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)。必须分配给调用者。

 

 


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值