2012-12-20 57 views
1

考慮下面的代碼和輸出:Android:爲什麼同樣重量的按鈕具有不同的寬度?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="ABCDE" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="A" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="ABC" /> 
    </TableRow> 

</TableLayout> 

enter image description here

的按鈕給出相同layout_weight,但具有不同的寬度。爲什麼他們不佔用相同的寬度?我能做些什麼來使它們具有相同的寬度(不給像素值)?

+3

用按鈕上的0dip更改layout_witdh,然後參閱。它適用於我 – Daler

+1

@Daler你可能想把它作爲答案。 ;) – Eric

+0

@Daler這似乎工作,但是什麼原因? – siva636

回答

3

layout_width更改爲0dip將解決此問題。

欲瞭解更多關於此原因或使用原因的信息,請查看explanation

很高興它幫助。

+0

@ prolink007,你做了太多的編輯... – Daler

+0

只是改善你的答案。拿出不需要的信息,併爲他的第二個問題添加了答案。如果您覺得編輯沒有用處,您可以隨時恢復它們。我的歉意,沒有任何編輯從你提供的答案中拿走了。它只會改善你的答案。 – prolink007

2

您可以將layout_width設置爲0dip,但如果文字太長,則不會太好。

相關問題