2011-05-27 42 views
1

button http://i54.tinypic.com/2cxvz1z.pngAndroid:如何佈局按鈕,使文本看起來像截圖中的一個?

請看看上面的截圖中,文本字符串是「刪除所選\ nMESSAGES」如果我用其父的LinearLayout的寬度/高度WRAP_CONTENT,文本看起來像:

DELETE

SELECTED

MESSAGES

(不每個字線之間的空間)

如果我使用匹配父項按鈕的寬度,它將被拉伸以匹配其父項,這不是我想要的。誰能幫我這個?

謝謝!

編輯:

按鈕的佈局:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:layout_margin="5dip" 
     android:paddingTop="5dip" 
     android:paddingBottom="0dip" 
     android:background="@drawable/solid_grey_btm_rounded"> 
     <Button 
      android:text="@string/delete_selected_messages" 
      android:id="@+id/btn_delete_message" 
      android:gravity="center" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:background="@drawable/button_grey_selector"> 
     </Button> 
</LinearLayout> 

我的工作在Android 2.3.3 API等級10,我在摩托羅拉Milestone(帶有實體鍵盤)測試

+0

它適合我。也許這會有所幫助,如果你說你使用的是哪個Android版本以及什麼Phone – 2011-05-27 08:52:00

+0

也許你可以使用固定寬度..你可以發送你的佈局代碼嗎? – Tima 2011-05-27 08:53:53

回答

0

我解決了這個問題,我將按鈕的layout_width和layout_height設置爲「match_parent」或「fill_parent」,同時還增加了邊距,使按鈕不完整填充其父項,添加填充以使文本變窄。

0

嘗試使用android:minLines="2",這應該有所幫助。

+0

我現在就試試。 – hzxu 2011-05-27 09:03:58

+0

我試了一下,用字符串中的新行字符,它仍然顯示三行,如果我刪除新行字符,它只是一行,並拉伸了按鈕的寬度。 – hzxu 2011-05-27 09:05:55

相關問題