Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically centering overlarge text in Android buttons

Android, Button view. The Button size is 38x38dp, text size is 20dp (just one + character worth of text). Gravity is set to center|center_vertically.

The text is NOT centered vertically. According to Android's internal accounting, the text is too large for the specified button size, so the text is placed with its top aligned with the top padding, and its bottom cut off. That's not what I want; I want the text to be cut evenly on the top and on the bottom. In other words, vertically centered. The plus character, since it takes less than a full-sized character cell, won't suffer from that.

It's Gravity that I set, not Layout gravity. I know the difference.

Any ideas how to make vertical centering work in such conditions, short of overriding draw()?

like image 638
Seva Alekseyev Avatar asked Dec 14 '11 16:12

Seva Alekseyev


1 Answers

Try adding android:includeFontPadding="false" to the Button view.

Some have suggested adding android:baselineAligned="false" to the container for similar problems but it didn't do anything for me.

like image 153
Glenn Avatar answered Sep 21 '22 04:09

Glenn