It is easy to baseline align text with images, but if you want the top of an image aligned with the top of your text,
it can be tricky. I wanted a solution that left
useFontPadding="true" so I would not crop any text.
I solved this by giving each TextView a negative margin such that the top of the text will be aligned to where the top of the TextView would have been.
// Do this immediately after inflating your TextView into a LinearLayout final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); final Paint.FontMetrics fontMetrics = textView.getPaint().getFontMetrics(); params.topMargin = -(int)(fontMetrics.descent - textView.getTextSize() - fontMetrics.top);
Find the right formula for the top margin was easy, thanks to: