How to remove TextView top margin?

Michal Chudy picture Michal Chudy · Dec 11, 2011 · Viewed 20.2k times · Source

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)

Answer

Maurycy picture Maurycy · Apr 18, 2012

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