#StackBounty: #android #textview #font-size #android-fonts #android-chips Manually calculating available width is incorrect when displa…

Bounty: 50

I have a ViewGroup with a Chip as a child with no horizontal siblings.

I try to calculate the available width before choosing which text to set inside the Chip.

final View parent = (View) getParent();
final int parentPaddingLeft = parent.getPaddingLeft();
final int parentPaddingRight = parent.getPaddingRight();
final int paddingLeft = getPaddingLeft();
final int paddingRight = getPaddingRight();
final int leftMargin = layoutParams.leftMargin;
final int rightMargin = layoutParams.rightMargin;
final int textViewSafetyPadding = 20;
final int currentTextMaxWidth =
    parentWidth
        - (textViewSafetyPadding
            + parentPaddingLeft
            + parentPaddingRight
            + paddingLeft
            + paddingRight
            + leftMargin
            + rightMargin);

It all worked well, but when I change the OS display size and font size to the largest – I see the chosen text doesn’t fit inside the Chip.

Even though the paint measurement and chip actual width show it should fit.

Chip’s width onDraw == 550pxl
chosen text requires 442pxl

and

paint.measureText(chipText) <= textMaxWidth

Any idea of abnormal extra padding when font size and display size are bigger than default?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.