Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the colon vertical center in TextView

I have a TextView showing time. The time updates every second.

I used DIN font. I have set TextView to center align(vertical). Why does the colon align to the baseline? Who knows how to fix this issue?

enter image description here


Update

               <TextView
                    android:id="@+id/time"
                    android:layout_width="wrap_content"
                    android:layout_height="48px"
                    android:layout_below="@id/temperature"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="-5px"
                    android:fontFamily="DIN"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="39px" />
like image 906
smallTong Avatar asked Aug 14 '15 02:08

smallTong


People also ask

How do you center TextView vertically?

android:gravity="center" for text center in TextView. android:gravity="center_horizontal" inner text if you want horizontally centered. android:gravity="center_vertical" inner text if you want vertically centered.

How do I center a TextView layout?

When you have a LinearLayout view, you can center the TextView widget by setting the layout_width and layout_height attributes of the TextView to match_parent and the gravity attribute to center . You can also center multiple TextView widgets by using the layout_weight attribute.

How do I center align text in XML?

To center align the text in this Textview through layout file, set the android:textAlignment attribute for the TextView to “center”, as shown in the following activity_main. xml layout file.


1 Answers

That is the default way how the font renders the colon character. There is no way in which you can change that, unless you create seperate TextViews for the colons. Alternatively you can use a different font and check if any of the other fonts actually centers the colon chararacter. Use the following to do this:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

For a better explanation of the fonts which can be used, you may check the official documentation.

Hope this helps :)

like image 128
Michele La Ferla Avatar answered Sep 20 '22 15:09

Michele La Ferla