将文本中心与android对齐

我知道这听起来很容易。我需要将一个文本放在中间,但是当文本太长时,它需要放在下面,但仍然在xml的中心对齐

这是我的密码:

<线性布局
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:id=“@+id/showdescriptioncontenttitle”
android:paddingTop=“10dp”
android:paddingBottom=“10dp”
android:layout\u centerHorizontal=“true”
&燃气轮机;
<文本视图
android:id=“@+id/showdescriptiontitle”
android:text=“Title”
android:textSize=“35dp”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
/&燃气轮机;
&lt/线性布局>

我把垫子放在顶部和底部,因为我需要一些空间。
PS:我的代码更大;它在一个相对的地方

还将TextView中的android:gravity参数设置为center

为了测试不同布局参数的效果,我建议为每个元素使用不同的背景色,这样您就可以看到布局是如何随重力、布局重力或其他参数变化的

发表评论