1

I want to remove extra padding from top and bottom of TextView. I try setIncludeFontPadding(false); and also this:

android:layout_marginTop="-Xdp"
android:layout_marginBottom="-Xdp

But they didn't work.

Is there any way to do that?

Saeed Masoumi
  • 9,349
  • 6
  • 55
  • 75
Taylor
  • 67
  • 1
  • 8

1 Answers1

4

setIncludeFontPadding works but it doesn't remove all padding, Specially when you wrap your text view size.

Create a custom TextView and override onDraw method then add these lines before calling super:

 @Override
    protected void onDraw(Canvas canvas) {
        float offset = getTextSize() - getLineHeight();
        canvas.translate(0, -offset); //or +offset to moving it to top
        super.onDraw(canvas);
    }
Saeed Masoumi
  • 9,349
  • 6
  • 55
  • 75