8

I give below attributes that I use textView in my application. ( Green text in middle )

<TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textStyle="bold"
                android:gravity="center_horizontal"
                android:text="10/9"
                android:id="@+id/estimate_fertility_date"
                />

However, there are spaces like the example picture. I want to set these spaces because when App initialize, It seems awful.

I have researched about 1 hour and I found some answers but They are not which I want answers. https://stackoverflow.com/a/6864017/2834196

enter image description here

Community
  • 1
  • 1
Olkunmustafa
  • 3,103
  • 9
  • 42
  • 55
  • Not sure what exactly you want to do but if you can't seem to set the spacing as you'd like, maybe first add android:includeFontPadding="false" to your textview so that the default pading doesn't factor into the spacing you desire, then set top/bottom padding or margin to the textview... – mjp66 Dec 29 '14 at 15:41

2 Answers2

5

It 's not easy to get absolutely no text padding in a normal TextView. One way is to can set a minus margin for the TextView, or just use textview.setIncludeFontPadding(false) to reduce padding to some degree.

Cimbali
  • 11,012
  • 1
  • 39
  • 68
Eager3466
  • 51
  • 1
  • 2
  • The only solution I found that actually did anything with my textview. But theres still some padding. – nilsi Sep 01 '20 at 06:49
4

Adding negative values to margin does it help you?

<TextView
android:layout_marginTop="-10dp" />
Zon
  • 18,610
  • 7
  • 91
  • 99
Sinan
  • 125
  • 1
  • 1
  • 6
  • I tried it and it worked but I'm not sure that this approach is exactly correct. Altough I am giving you one point :) – Olkunmustafa Dec 31 '14 at 11:30
  • Well, What if `TextView` contains multiple lines ? this is not a right solution. `lineSpacingExtra` would be the right option I think. – Suryavel TR Sep 24 '18 at 10:09