Android Java Text没有居中

时间:2012-11-03 06:20:32

标签: java android

我正在努力使文字全部居中,但它没有成功。这是我的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

6 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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" />

答案 2 :(得分: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"
        />

答案 3 :(得分:0)

首先,您需要使用新行和所有格式设置文本格式 而且比删除

之类的inxml文件有些变化
  

机器人: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"
 />

这里我没有格式化文本。

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

答案 4 :(得分:0)

尝试添加:

android:layout_gravity="center"

答案 5 :(得分: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的最小宽度并将其居中于其父级