Reputation: 680
I have some code that should center a text in button, but the text is not aligned exactly in the middle. It is located a little at the bottom. How I could fix this?
</style>
<style name="ButtonText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">34dp</item>
<item name="android:layout_weight">0.5</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:padding">1dp</item>
<item name="android:textSize">26sp</item>
<item name="android:textStyle">bold</item>
</style>
<Button
android:id="@+id/buttonStop"
android:background="@drawable/greenbutton"
style="@style/ButtonText"
android:text="@string/ButtonStop" />
Upvotes: 2
Views: 85
Reputation: 1423
I guess must be contradict in your style. Change your padding and layout_height attributes to following.
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
Upvotes: 0
Reputation: 22342
This is normal. Text generally has top/bottom padding that isn't even. It's used for ascender/descender area.
If you need pixel-perfect centering, you can try telling it not to include the font padding with:
android:includeFontPadding="false"
Upvotes: 1