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?
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" />
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.
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.
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With