Code example for Paint

Methods: ascent, descent

0
    private int measureHeight(int measureSpec) {
        int result;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);
 
        ascent = (int) textPaint.ascent();
        if (specMode == MeasureSpec.EXACTLY) {
            // We were told how big to be 
            result = specSize;
        } else { 
            // Measure the text (beware: ascent is a negative number) 
            result = (int) (-ascent + textPaint.descent()) + getPaddingTop()
                    + getPaddingBottom();
            if (specMode == MeasureSpec.AT_MOST) {
                // Respect AT_MOST value if that was what is called for by measureSpec 
                result = Math.min(result, specSize);
            } 
        } 
        return result;
    }