Menu

1 / 2

Fitting a Home-screen clock between widgets in Jetpack Compose: measure first, binary-search the font size, keep a floor

DEV Community: kotlin·ReClaim·about 7 hours ago
#sVsNVRfa
#devtokotlin#devto#dev#size#clock
Long article (2578 words) — no AI summary yet.
Reading 0:00
15s threshold

We're building ReClaim , a minimalist Android launcher that's on Google Play . The biggest thing on its Home screen is a clock. When the clock has the screen's width to itself, a fixed font size is fine.

But Home also has small optional widgets: habit marks, a practice timer, a block status. They sit in a row on either side of the clock, and the clock gets whatever width is left. With a fixed 64 sp clock and TextOverflow.Ellipsis , a narrow phone with marks on both sides could end up showing something like "10:…". A clock that hides its own minutes isn't much of a clock.

This post walks through the fix: measure the text with Compose's TextMeasurer , binary-search the largest font size that fits, and keep a floor where we stop shrinking. It's a small function, but a few of its choices are easy to get wrong, and some side effects only showed up when we read it closely for this post.

One version note first. This code landed in our repo on November 25, 2026.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.