如何在Android中一个TextView水平和垂直居中文本? [英] How do I center text horizontally and vertically in a TextView in Android?

查看:867
本文介绍了如何在Android中一个TextView水平和垂直居中文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在水平和垂直居中的文本在的TextView 在Android中,使其恰好出现在的的TextView

How do I center the text horizontally and vertically in a TextView in Android, so that it appears exactly in the middle of the TextView?

推荐答案

我在你使用XML布局假设。

I'm assuming you're using XML layout.

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"
    android:text="@string/**yourtextstring**"
/>

和作为@stealthcopter评论 在Java中: .setGravity(Gravity.CENTER);

and as @stealthcopter commented in java: .setGravity(Gravity.CENTER);

这篇关于如何在Android中一个TextView水平和垂直居中文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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