Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove TextView top margin?

I do have a problem with TextView. I don't want to have any margin/padding above it.

<TextView android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:id="@+id/ptp_hour"           android:textColor="@color/black"           android:textSize="100dp"           android:height="100dp"           android:layout_marginTop="0dp"           android:paddingTop="0dp"           android:includeFontPadding="false"           android:maxLines="1"           android:text="10"/> 

My TextView looks like this and despite the textSize and height are set to the same value, there is a space above font. It bothers me because I want to put another view relatively to the top of the font. Is this spacing included into font itself?

TextView in RelativeLayout

And another question: If I found out that margin 20dp from top and 7dp from bottom works perfectly on my device, can I rely that it will behave in a similar way on other screens? (these margins are for buttons)

like image 470
Michal Chudy Avatar asked Dec 11 '11 17:12

Michal Chudy


People also ask

How to remove extra space in TextView android?

This example demonstrates How to remove white spaces for textview in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

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.

What is lineSpacingExtra?

The difference is that android:lineSpacingExtra add extra spacing between lines of text of TextView and android:lineSpacingMultiplier work as scale factor for height of line space. in other words, each line height will be height*multiplier + extra. Follow this answer to receive notifications.


1 Answers

using android:includeFontPadding="false" helped me a lot in a similar situation.

like image 166
Maurycy Avatar answered Oct 18 '22 18:10

Maurycy