如何在Android中一个TextView水平和垂直居中文本?文本、如何在、水平和、TextView

2023-09-12 21:32:36 作者:把权天下

我如何在水平和垂直居中的文本在的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);

 
精彩推荐