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?
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)
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.
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.
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.
using android:includeFontPadding="false"
helped me a lot in a similar situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With