Code example for StaticLayout

Methods: drawgetLineCount

    private int getTextLineCount(CharSequence source, TextPaint paint, int widthPx, float textSize) {
        // Update the text paint object 
        // Draw using a static layout 
        StaticLayout layout = new StaticLayout(source, paint, widthPx, Layout.Alignment.ALIGN_NORMAL, mSpacingMult,
                mSpacingAdd, true);
        try { 
        } catch (Exception e) {
            return 1; 
        return layout.getLineCount();
    // Set the text size of the text paint object and use a static layout to render text off screen before measuring 
    private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
        // Update the text paint object