Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the top and bottom space on textview of Android

When I include the below XML to layout file, I can see the below image. If you see it, you could realize that the TextView has top and bottom space.

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="E1" android:background="#ff00ff00"/> 

enter image description here

I wish to remove the space. How to remove it? What is it called? If anyone has clue.. please let me know. Thanks in advance.

like image 919
mooongcle Avatar asked Jul 06 '11 08:07

mooongcle


People also ask

How do I Auto Resize TextView?

To use preset sizes to set up the autosizing of TextView in XML, use the android namespace and set the following attributes: Set the autoSizeText attribute to either none or uniform. none is a default value and uniform lets TextView scale uniformly on horizontal and vertical axes.

What is includeFontPadding?

You can use android:includeFontPadding="false" to get rid of the default padding in a TextView . Android docs say this about the attribute: Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.


1 Answers

Try android:includeFontPadding="false" to see if it helps. In my experience that will help a little bit, but there's no way of reducing the TextView dimensions to the exact pixel-perfect text size.

The only alternative, which may or may not give better results, is to cheat a bit and hard-wire the dimensions to match the text size, e.g. "24sp" instead of "wrap_content" for the height.

like image 103
Graham Borland Avatar answered Sep 20 '22 13:09

Graham Borland