How do I center the text horizontally and vertically in a | ||||
I'm assuming you're using XML layout.
| ||||
will do the trick | ||||
You can also set it up dynamically using:
| |||
This works when used with a RelativeLayout where the layout's height & width are set to wrap_content. | ||||
If you are using TableLayout make sure to set the gravity of the TableRows to center, too. Otherwise it will not work. At least it didn't work with me until i set the gravity of the TableRow to center. For Example like this: | |||
In my opinion,
is better than,
which is better than,
at least for formatting text. | ||||
you need to set TextView Gravity (Center Horizontal & Center Vertical) like this
and
and dynamically using:
| ||||
If you are trying to center text on a TableRow in a TableLayout, here is how I achieved this:
| |||
You cab also use combination:
Then, if textview width is more than "fill_parent" the text will be still aligned to left (not centered as with gravity set only to "center"). | |||
I used the Even iOS 3.0 was very good at things like this :"| | ||||
In Relative layout, it will be nice with it. and another button and anything else you can add.
works nicely for me. | |||
I'm setting the height of the textview and can't get the text to center vertically. It stays at the bottom of the textview. Code is below but is not formatting correctly in this post (even though each line preceeded by 4 spaces). Problem seems to be that I set textview layout_height to 20dp. If I change layout_height to wrap_content: the text does center vertically - but it's too high for my needs. The textview is in a relative layout and has layout_centerVertical="true" and gravity="center_horizontal|center_vertical". I've also tried android:gravity="center" and tried omitting the centerVertical + many other options. | ||||
This worked better for me: android:layout_gravity="center". The other way mentioned works but in a few test apps was being overriden. This worked better for me. | |||
you can just set the gravity of your textview into CENTER. | |||
just use | ||||
You can set textview in horizontaly and vartically using below method. add one layout set the layout gravity horizontal and vertical and add the textview in that layout so you have textview in center horizontal and vartical | |||
default
.
forum.xda-developers.com
No comments:
Post a Comment