Code example for TextPaint

Methods: ascent, descent

0
			// We were told how big to be, so nothing to do. 
			result = specSize;
		} else { 
			// The lines should already be broken up. Calculate our max desired height for our current mode. 
			int numLines = textBreaker.getLines().size();
			float lineHeight = -textPaint.ascent() + textPaint.descent();
			result = (int) (numLines * lineHeight + getPaddingTop() + getPaddingBottom());
 
			// Respect AT_MOST value if that was what is called for by measureSpec. 
			if (specMode == MeasureSpec.AT_MOST) {
				result = Math.min(result, specSize);
			} 
		} 
		return result;
	} 
	 
	private int breakWidth(int availableWidth) {
		int maxW = availableWidth - getPaddingLeft() - getPaddingRight();
		textBreaker.setMaxWidthLines(maxW, maxLines);
		return (int) Math.ceil(textBreaker.breakText(text, textPaint)) + getPaddingLeft() + getPaddingRight();
	}