2011-04-13 52 views
2

我有一個textview,對於某些情況下它有長文本。對於長文本,它看起來很長,以至於它扭曲了總體佈局。我想要長文本,它應該出現在多行。這裏是TextView的xmlAndroid TextView問題

<TextView 
      android:id="@+id/bottomText" 
      android:layout_height="wrap_content" 
      android:textColor="#FFFFFF" 
      android:background="#000000" 
      android:textSize="16sp" 
      android:layout_gravity="center_horizontal" 
      android:text="@string/text_searchword" 
      android:layout_width="wrap_content"> 
</TextView> 

這個問題的解決方案是什麼?

回答

0

設置android:lines屬性,如Heiko Rupp指出,也設置android:maxLenghtandroid:maxEms也。

兩者都會將您的TextView限制爲最大x個像素或密度獨立像素或相應的x ems。

+0

是可能的,如果需要(即長文本)使字體大小小,容納它的一個線? – 2011-04-13 13:57:03

+0

不是沒有一些Java代碼。 – 2011-04-13 14:13:59

1

您可以嘗試添加屬性行:

android:lines="4" 

而且wrap_content可能不適合寬度的最佳選擇。檢查fill_parent

0

您可以嘗試設置android:layout_width =特定的尺寸。

0

我認爲重心位置設定在XML文件「中心」可能會做的工作:

android:gravity="center"