Vertically centering overlarge text in Android buttons
Asked Answered
M

1

6

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()?

Manna answered 14/12, 2011 at 16:27 Comment(2)
Did you find a resolution to this? I have the exact same problem.Rightward
Same problem here, except im using TextViews. Text is too low on the button if the size is large. Been googling for solutions off and on for over two weeks. Ive been thinking about using a layout for my button and then a textview inside. Instead of one TextView.Pedersen
R
5

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.

Rightward answered 20/4, 2012 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.