我知道这听起来很容易。我需要将文本放在中间,但是当文本太长时,它需要放在下面,但仍然在我的xml中心对齐。将文本中心与android对齐
这里是我的代码:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/showdescriptioncontenttitle"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_centerHorizontal="true"
>
<TextView
android:id="@+id/showdescriptiontitle"
android:text="Title"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
我把paddingTop和底部,因为我需要一些空间。 PS:我的代码更大;它在RelativeLayout中。
谢谢你,它的工作,只是需要一些时间来有效的回答! – Tsunaze
我看到android:layout_centerHorizontal =“true”不再需要了.. – Tsunaze
是的,那是真的。但我认为只有当TextView有多行时才行。因为只有1个不是全行的文本,TextView不会横向填充布局 –