2011-04-04 77 views
0

我有一排按鈕與自定義9修補圖像和可變長度文本。我希望按鈕的高度相同。當文本足夠長以包裝時,它會擴展按鈕大小,使得包裝文本的按鈕比其他文本更大。我將這些按鈕放在線性佈局的代碼中。我可以修復按鈕的大小,但它只是切斷了底部。我怎樣才能使文本佔用更多的按鈕的填充空間,使文本對齊按鈕的頂部行?如何讓按鈕文字擴展到9補丁內容區域之外?

回答

0

最終我無法找到一個不需要創建自定義視圖類的好方法。

1

9patch內容區域僅用於設置填充。如果你改變按鈕的填充,你將覆蓋9patch設置的那個。

編輯

嘗試這樣:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <Button android:text="ButtonButton" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:paddingTop="0dp" 
     android:paddingBottom="10dp"/> 
    <Button android:layout_width="wrap_content" android:text="Button" 
     android:layout_height="match_parent"/> 
    <Button android:layout_width="wrap_content" android:text="Button" 
     android:layout_height="match_parent"/> 
</LinearLayout> 

這樣的按鈕將高達別人。不幸的是,我不知道它是否取決於原始按鈕的9patch可能有不對稱的填充,但我不能讓文本與其他按鈕的文本對齊(我認爲重力默認設置爲中心)。可能與你的9patch雖然工作。 (編輯:哦,但如果你將有兩行文字誰在乎對齊)

+0

使用setPadding(0,0,0,0)設置填充會產生影響,但目前爲止還不是很好。它向下移動按鈕的頂部,並切斷按鈕文本的底部。我想要做的就是向上移動文本,不調整背景圖像,但我明白它們是相關的。 – 2011-04-04 16:55:33

+0

@Micah編輯答案 – bigstones 2011-04-04 17:28:55

+0

不管我怎麼試,在9修補程序使用的東西之下改變填充似乎只是搞砸了繪圖。我很欣賞你採取這種方式幫助我的時間。 – 2011-04-04 18:25:16