Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Gtk, how do I center the text within a TextView vertically?

Tags:

c#

gtk

gtk#

If I just make a standard TextView with the Justification set to Center, it looks something like this:

Center-Justified TextView

If I also want to center the text vertically, as well as horizontally, how do I do this?

like image 627
Matthew Avatar asked Jan 18 '10 01:01

Matthew


People also ask

How do you center text in a TextView?

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 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.

How do I make text vertical on Android?

We will start off with creating a custom TextView extending android's TextView class, call it VerticalTextView. The key to the vertical text view is the rotation. Inside the custom class, we define a constant 270f or 90f depending on how you want the text to be read which is the rotation angle.


2 Answers

You may be able to fudge such an alignment by dynamically updating pixels-above-lines based on the size of the textview control and the size of the text being displayed in it.

like image 168
zeFrenchy Avatar answered Nov 05 '22 19:11

zeFrenchy


TextViews are normally meant for a large amount of text that the user can edit. As such it may grow too large and have to scroll, hence the difficulty with vertical centering.

If you're only using it to display a message that doesn't have to be edited, you might try Gtk.Label instead, which you can center vertically.

like image 23
ptomato Avatar answered Nov 05 '22 18:11

ptomato