Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected top and bottom padding on a TextView?

Tags:

android

I have a TextView. I want to set its background color. But the color fills more top space than it does bottom space.

<!-- red background. -->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    android:textStyle="bold"
    android:background="#f00"
    android:text="10.0" />

This is how it renders (zoomed in to demonstrate, green lines added by me):

enter image description here

So the extra space up top makes it look like the text is not centered within its own container. Is this expected? I'd like the text to appear vertically centered within its own container (the red area).

This is on a galaxy nexus, stock version of jellybean.

Thanks

like image 399
user291701 Avatar asked Dec 21 '22 12:12

user291701


1 Answers

Add the following attribute:

android:includeFontPadding="false"
like image 99
Flávio Faria Avatar answered Jan 04 '23 22:01

Flávio Faria