2012-04-19 74 views
0

我有一個關於我的Android應用程序的佈局一個奇怪的問題(我正在學習,所以ofcourse我正在做一個計算器:))。我將所有按鈕指定爲行寬度的25%,但是當我在頂部添加EditText時,第一列變得比其他三列寬很多。 (屏幕截圖來自IntelliJ預覽版,但是當我在我的設備上加載應用程序時,結果顯示如下:奇怪的佈局行爲 - layout_weight和按鈕

當我刪除EditText時,此問題消失了,我嘗試在XML中向EditText添加重量屬性無濟於事

結果:

The result

我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
    <TableLayout android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:weightSum="1.0"> 
     <TableRow android:layout_width="fill_parent" 
        android:weightSum="1.0"> 
      <EditText android:layout_weight="1.0" 
         android:text="Edit me"></EditText> 
     </TableRow> 
     <TableRow android:layout_width="fill_parent" 
        android:weightSum="1.0"> 
      <Button android:text="7" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="8" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="9" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="/" 
        android:layout_weight="0.25"></Button> 
     </TableRow> 
     <TableRow android:layout_width="fill_parent" 
        android:weightSum="1.0"> 
      <Button android:text="4" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="5" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="6" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="*" 
        android:layout_weight="0.25"></Button> 
     </TableRow> 
     <TableRow android:layout_width="fill_parent" 
        android:weightSum="1.0"> 
      <Button android:text="1" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="2" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="3" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="-" 
        android:layout_weight="0.25"></Button> 
     </TableRow> 
     <TableRow android:layout_width="fill_parent"> 
      <Button android:text="0" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="." 
        android:layout_weight="0.25"></Button> 
      <Button android:text="+/-" 
        android:layout_weight="0.25"></Button> 
      <Button android:text="=" 
        android:layout_weight="0.25"></Button> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

由於在dvance。

回答

1

如果您編輯文本填滿屏幕的整個寬度,爲什麼不把你的表外?喜歡這個?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
    <EditText android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
         android:text="Edit me"/> 
    <TableLayout android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:weightSum="1.0"> 
     <TableRow android:layout_width="fill_parent" 
        android:weightSum="1.0"> 
      ... 
+0

呀,這應該工作。你更快:) – 2012-04-19 14:26:04

+0

黃金!我忘了方向,這就是爲什麼我沒有注意到這種方式。謝謝。 – Hidde 2012-04-19 14:34:05