Center large font in TextView

I have a problem that seems pretty trivial, but I have not been able to solve it yet.

I have a full-screen album in which I have one LinearLayout containing two TextViews that occupy half the screen each. One of the TextViews must have a centered character, regardless of font size.

The problem is that when I increase the font size of this symbol, it is not centered, but instead has its center below the center line of the screen.

Here is activity with a 200sp symbol on a 800 * 480 screen, it looks normal - the symbol is centered:

http://i122.photobucket.com/albums/o251/px_seven/char_200_sp.jpg

Here is the activity with a 300sp symbol, now the character has moved down:

http://i122.photobucket.com/albums/o251/px_seven/char_300_sp.jpg

This is the layout (I change the default font size to 250sp in the code):

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:keepScreenOn="true"> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:layout_gravity="center" android:gravity="center_horizontal" android:background="#000000" /> <TextView android:id="@+id/tv2" android:lines="1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:layout_gravity="center" android:gravity="center" android:background="#000000" android:text="N" android:textSize="250sp" /> </LinearLayout> 

Does anyone see what the problem is?

Thanks, Fredrick

+6
source share
1 answer

Try adding this attribute to your android:includeFontPadding="false" text view android:includeFontPadding="false"

+12
source

Source: https://habr.com/ru/post/908650/


All Articles