我知道這聽起來很容易。我需要將文本放在中間,但是當文本太長時,它需要放在下面,但仍然在我的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不會橫向填充佈局 –