屏幕中央的TextView [英] TextView in the center of the screen

查看:84
本文介绍了屏幕中央的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何将文本水平居中并在Android的TextView中垂直放置?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆