1. 程式人生 > >Android 基礎 之 getTextBounds

Android 基礎 之 getTextBounds

該方法的作用時顯示字元的顯示範圍? 怎麼個顯示範圍呢?
Rect rect = new Rect();
// 獲取字型的顯示範圍,這個顯示範圍是隻跟字型大小和字元長度有關的屬性
// 不管字元是否被畫出,這個顯示範圍的屬性都存在
// 可以看到getTextBounds在drawText之前呼叫的,還是可以獲得資料
paint.getTextBounds(mText,0,mText.length(),rect);
Log.d(TAG, "rect:"+rect.toString());
canvas.drawText(mText, x,y,paint);