2011-05-01 99 views
2

我有一個表佈局shown.I有很多行。我已經使用android:strechcolumns =「1」來拉伸每一行的第二列。這就是無處不在的情況。表佈局大小

但在第五行我有2個fields.I希望他們佔據等於space.The行大小應該是相同以前row.I的希望行的整體尺寸保持相同的screeshot.Also我已經在屏幕截圖中指出了所有行應該位於的邊界。

這怎麼辦?

<TableRow> 
    <TextView 
     android:gravity="right" 
     android:paddingTop="10dip" 
     /> 
    <Spinner 
    android:id="@+id/depot_name_spinner"/> 
</TableRow> 

<TableRow> 
    <TextView 
    android:text="@string/product_name" 
    android:paddingTop="10dip" 
    android:gravity="right"/> 
    <Spinner 
    android:id="@+id/product_name_spinner" 
    /> 
</TableRow> 

<TableRow> 
    <TextView 
     android:text="@string/date" 
     android:gravity="right" /> 
    <Button 
    android:id="@+id/date_button" /> 
</TableRow> 

<TableRow> 
    <TextView 
     android:text="@string/measure_ltr" 
     android:gravity="right" 

     /> 
    <EditText 
    android:id="@+id/ltr_text" 
    android:layout_width="50dip"/> 
    <TextView 
     android:text="@string/measure_qts" 
     android:gravity="right" 
    /> 
     <EditText 

    android:id="@+id/qts_text" 
    /> 
</TableRow> 

enter image description here

感謝

回答

2

您不僅可以TableRow添加到表中。只需使用一個簡單的LinearLayout並將所有原始內容放入其中。我認爲它必須解決你的問題。

編輯:另外,您可以用LinearLayout所有小工具添加到TableRow並設置LinearLayoutandroid:layout_span=2

<TableRow> 
    <LinearLayout 
     android:layout_span="2"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/measure_ltr" 
      android:gravity="right"/> 
     <EditText 
      android:id="@+id/ltr_text" 
      android:layout_width="50dip" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/measure_qts" 
      android:gravity="right"/> 
     <EditText 
      android:id="@+id/qts_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</TableRow> 

我還沒有嘗試過,但希望它會工作。

+0

我使用的時刻,但不能複製,你知道,我在錶行使用STRECH列構成行的默認大小暢遊以前row.Do的確切高度? – rogerstone 2011-05-01 09:50:45

+0

我不知道如何獲得'TableRow'的默認高度。但我增加了另一個答案的答案。 – Michael 2011-05-01 10:17:17

+0

檢查了你給我的那段代碼。看起來像android:span不適用於線性佈局。我檢出了文檔。它不在那裏.xml給了我一個錯誤。 layout_span'可以在錶行內使用,但其值必須在引號: – rogerstone 2011-05-03 15:13:15

1

嘗試使用機器人:體重。一旦佈局佈局完成後,這將劃分剩餘的空間,而這正是您想要的。我的意思是你可以定義每個視圖應該使用的空間比例。看看下面的這個例子。

<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <TableRow> 

    <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" 
        android:layout_height="wrap_content" android:weightSum="100">  // Mention Weightsum as 100 so that its easy to split among your views. 

     <TextView android:id="@+id/row1Label" 
      android:layout_width="0dip" android:layout_weight="60"  // This will occupy 60% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

     <TextView android:id="@+id/row1Label" 
      android:layout_width="0dip" android:layout_weight="40"  // This will occupy 40% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

    </LinearLayout> 

    </TableRow> 

    <TableRow> 

    <LinearLayout android:layout_width="fill_parent" android:orientation="horizontal" 
        android:layout_height="wrap_content" android:weightSum="100"> 

     <TextView android:id="@+id/row2Label" 
      android:layout_width="0dip" android:layout_weight="60"  // This will occupy 60% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 

     <TextView android:id="@+id/row3Label" 
      android:layout_width="0dip" android:layout_weight="40"  // This will occupy 40% of the remaining space 
      android:layout_height="wrap_content"> 
     </TextView> 


     // You can more views and distribute the space accordingly.... 

    </LinearLayout> 

    </TableRow> 

...........

有了這個,你可以做到這樣的事情 enter image description here

您可以分割在任何你想要的方式錶行區域。這可以僅使用線性佈局來完成,因爲其他佈局沒有這種權重選項。我廣泛使用這種方法來創建複雜的視圖。希望它可以幫助你。