屏幕中央的TextView [英] TextView in the center of the screen
问题描述
Possible Duplicate:
How do I center text horizontally and vertical in a TextView in Android?
我有一个RelativeLayout
(在它之前是LinerLayout
),它占据了所有屏幕,我想在这个Layout
的中间放置一个TextView
.我尝试用gravity = "center"
layout_gravity = "center"
以及其他一些方法来做到这一点,但这是行不通的.
I have a RelativeLayout
(before it was a LinerLayout
), that occupies all the screen and I want to put in the center of this Layout
, a TextView
. I try to do it with gravity = "center"
layout_gravity = "center"
and a few more, but it doesn't work.
有人知道如何将TextView
放在屏幕中间吗?
Anybody knows how to center the TextView
in the middle of the screen?
编辑
好的,我想我解释得很糟糕.我认为TextView
位于中心,但是我想居中的是TextView
中的文本.我可以这样做吗?
Ok, I think I explained badly. I think the TextView
is in the center, but what I want to center is the text in the TextView
. Can I do this?
推荐答案
如果字体大小足够大,则由于字体填充而使其看起来好像没有居中.
尝试将已提及的属性与android:includeFontPadding
结合使用,如下所示:
If your font size is big enough, it might look like it's not centered, because of the font padding.
Try using the already mentioned properties combined with android:includeFontPadding
, something like this:
android:gravity="center"
android:includeFontPadding="false"
这篇关于屏幕中央的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!