如何在Android的TextView中将两行文本居中? [英] How to center a two-line text in a TextView on Android?

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

问题描述

我想让它看起来像这样:

I want to let it looks like this:

|    two    |
|   lines   |

这是当前布局,根本无法使用.

Here is the current layout, not working at all.

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="two\nlines"
        android:layout_gravity="center_vertical"
        android:layout_centerInParent="true"/>
</RelativeLayout>

有什么主意吗? 谢谢!

Any idea? Thanks!

推荐答案

如果只想居中(我假设\n正在拆分行),只需添加android:gravity="center_horizontal"而不是.
使用布局重力会移动实际的TextView,使用重力会影响TextView的内容.

If you just want to center it (I'm assuming the \n is working to split the lines), just add android:gravity="center_horizontal" rather than layout_gravity.
Using layout gravity moves the actual TextView, using gravity affects the content of the TextView.

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

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