#StackBounty: #android #html #css #font-size CSS: scale non-text elements based on the system's font size

Bounty: 100

I’m trying to limit an element to 2 lines of text and I wanted a fallback for -webkit-line-clamp. This solution works when the system’s default font size is the default:

line-height: 1.3em;
max-height: 2.6em;
overflow: hidden;

However, on Android, if I change the system’s font size, the bottom of the second line is cut off:

enter image description here

enter image description here

The font-size is 16px, but with Android’s scaling (1.3x), the computed styles are:

font-size: 20.8px;
line-height: 27.04px;
max-height: 41.6px;

So it looks like font-size and line-height are scaled, but not max-height. Since max-height is based on em, I expected it to scale too. Is there a way to make this work?


Get this bounty!!!

#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!!!