【发布时间】:2013-12-27 20:45:35
【问题描述】:
我需要文本位于屏幕的直接中心,并希望 textview 填充父级。但它一直将文本的开头对齐到屏幕的中心。
在android中使用textview时如何使文本居中?
这就是我所拥有的
这是xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center" //removing this line has no effect
android:gravity="center"
android:text="TextView" />
</RelativeLayout>
-------------------------------------
【问题讨论】:
-
PS:请注意,我确实使用了
android:gravity="center",所以请不要将其称为任何给出答案的内容
标签: java android xml textview android-relativelayout