How to remove TextView top margin?
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);}