1

我正在尝试使文本全部居中,但没有成功。这是我的xml代码

<TextView
android:id="@+id/creditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff"
android:layout_marginLeft="0dp"
android:layout_marginTop="350dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer 
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
 />

相反,它只是变得混乱起来。

这就是它的样子 http://i.imgur.com/DVNua.png

4

6 回答 6

1

您在这些名称之间给出了空格。我假设您想要一个位于页面中心的垂直名称列表。在这种情况下,在每个名称的末尾,而不是空格,按 Enter 键,这样您就会得到一个换行符。然后,您可以获得一个很好的居中垂直名称列表。

于 2012-11-03T06:25:40.867 回答
0

试试这个:

<TextView
        android:id="@+id/creditText"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp"
        android:gravity="center"
        android:maxLines="6"
        android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer 
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
        android:textColor="#ffffff"
        android:textSize="20dp" />
于 2012-11-03T06:28:13.420 回答
0

可能有用此代码

        <TextView
        android:id="@+id/creditText"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="350dp"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="20dp"
        android:maxLines="6"
        android:text="Dalton 
                   Metlzer: Lead Programer/Designer\n
                   Cole Selensky: Lead Designer/Programer\n 
                   Carson Rego: Lead Artist\n
                   Carly R: Logo Artist\n
                   Evan Swonke: Music Composer/Performer\n
                   Blake Jackson: Narator"
        />
于 2012-11-03T06:34:34.293 回答
0

首先,您需要用换行符和所有内容格式化文本,而不是像删除这样的 XML 文件中的一些更改

android:layout_marginTop="350dp"

像这样的新xml代码

 <TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="20dp"
android:textColor="#000000"
android:layout_marginLeft="0dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer 
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
 />

这里我没有格式化文本。

根据您的要求格式化文本。

于 2012-11-03T06:41:37.733 回答
0

尝试添加这个:

android:layout_gravity="center"
于 2012-11-03T07:53:22.587 回答
0

android:gravity 属性在 TextView 的内容中生效,但由于您也有 android:layout_width="wrap_content" 您没有居中位置。

要么放

android:gravity="center"
android:layout_width="match_parent"

在内部增长 TextView 和中心,或

android:layout_gravity="center_horizontally"
android:layout_width="wrap_content"

保持 TextView 的最小宽度并将它的中心放在它的父级上

于 2012-11-03T10:50:01.930 回答