Android native implementation of Figma's Vertical Trim feature

Our team is working on a design system where we need to replicate Figma’s Vertical Trim functionality in Android.

I’m struggling to find a proper way to remove the extra vertical spacing from TextViews that appears above and below the actual text content. This spacing makes it hard to achieve pixel-perfect designs that match our Figma mockups.

What I’ve tried so far:

Using android:includeFontPadding="false" but this approach has problems:

  • It cuts off accented characters like Ą or Ź
  • Bottom spacing still remains visible
  • Doesn’t work consistently across different font families

Example of the issue:

<TextView
    android:id="@+id/titleText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sample Header Text"
    android:textSize="24sp"
    android:includeFontPadding="false"/>

Even with includeFontPadding set to false, there’s still unwanted vertical space that prevents accurate spacing between UI elements.

Is there a native Android solution to achieve true vertical text trimming similar to what Figma offers?

I hit this same problem building our design system last year. What finally worked was using Paint.getTextBounds() to calculate text bounds manually, then adjusting TextView padding in code. You measure the actual text dimensions and apply negative padding to fix font metric differences. This handles accented characters way better than includeFontPadding. The trick is nailing the baseline offset and getting ascent/descent values right. Takes some math, but you’ll get pixel-perfect control that actually matches your Figma layouts across different fonts and sizes.

you can also try using a custom view that overrides onMeasure. that way, you can get exact heights needed without the extra padding. it might take some tinkering, but it’s doable!