2011-02-18 34 views

回答

5

我會認爲上行和下行高度通常是相同的,但我不會依賴它爲每個字體。我真的沒有看到直接到達x高度的方法,但是你可以使用的技巧如下所示。另外,對於總高度,你是在談論從最高上升到最低下降的絕對距離?我還在下面列出了一些東西。我沒有測試這些我自己,但它應該工作(但讓我知道如果我誤解的東西你說):

// Assuming TextPaint/Paint tp; 
Rect bounds; 

// this will just retrieve the bounding rect for 'x' 
tp.getTextBounds("x", 0, 1, bounds); 
int xHeight = bounds.height(); 

Paint.FontMetrics metrics = tp.getFontMetrics(); 
int totalHeight = metrics.top - metrics.bottom; 
1

這是對我工作:

​​
相關問題