Skip to content

Doesn't work when increasing the view's height. #7

@sebouh00

Description

@sebouh00

Here's how to fix it.

private float findNewTextSize(int width, int height, CharSequence text) {
        TextPaint textPaint = new TextPaint(getPaint());
        float targetTextSize = getMaxTextSize();  // Start from the max size
        int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
        while(textHeight > height && targetTextSize > mMinTextSize) {
            targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
            textHeight = getTextHeight(text, textPaint, width, targetTextSize);
        }
        return targetTextSize;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions