2012-11-03 28 views
1

我試圖讓所有的文字都居中,但沒有解決。這是我的xml代碼Android Java文本不居中

<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

+0

重新寫的android :layout_marginTop =「0dp」 – ckpatel

+2

我剛剛複製你的代碼&它正在尋找中心 –

+0

只做一件事ctrl + A >> ctrl + shift + F&刪除頂部邊距 –

回答

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" 
     /> 
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" /> 
0

所有你需要你的文本新行格式和所有 的第一,比一些變化inxml文件like remove

android:layout_marginTop =「350dp」01這樣

<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" 
/> 

新的XML代碼在這裏,我不格式化文本。

根據您的要求設置文本格式。

+0

事情是我有文字向上滾出屏幕的底部,這就是爲什麼即時通訊它在350 –

+0

好吧我明白,你應該將該行添加到您的代碼和格式的文本根據您的要求,也工作正常。 –

0

嘗試添加此:

android:layout_gravity="center" 
0

了android:重力屬性生效的TextView中的內容,但你也有機器人:layout_width =「WRAP_CONTENT」你不必在哪裏集中在。

要麼把

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

增長TextView的和內部中心,或

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

保持的TextView的最小寬度和中心它在它的父