Question

I am using following code to center the text in textview.

<TextView android:layout_height="20dp" 
android:layout_width="20dp" 
android:text="?"
android:id="@+id/tv281"
android:textSize="18sp"
android:background="@drawable/qcircle"
android:gravity="center"
android:layout_marginRight="5dp"
></TextView>

But the "?" is not vertically centered. What is wrong ?

Was it helpful?

Solution

The text is already centered vertically, but the layout height is too small, or textSize too big, change that

edit

this is better

android:includeFontPadding="false"

the problem is that the text font is too big for the layout height, then you can change this values, but also the problem is the padding of the layout, if you put android:padding="0dp" won't work, because the padding of the font, the best solution is not to include de font's padding in the TextView

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top