How to remove TextView top margin? How to remove TextView top margin? android android

How to remove TextView top margin?


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


I had the same issue where setting android:includeFontPadding=false did not help. The best solution I could find in reasonable time was to override the TextView's onDraw method and to adjust the canvas for the difference between the font metrics' top and ascent values:

FontMetricsInt fontMetricsInt;@Overrideprotected void onDraw(Canvas canvas) {    if (adjustTopForAscent){        if (fontMetricsInt == null){            fontMetricsInt = new FontMetricsInt();            getPaint().getFontMetricsInt(fontMetricsInt);        }        canvas.translate(0, fontMetricsInt.top - fontMetricsInt.ascent);    }    super.onDraw(canvas);}


What you need to do is to put the other view relative to the top of the font, and give it a negative android:layout_marginBottom in dip, such that it matches the top of the font. If the font has a margin, I don't think there is a better way of doing it.