2013-07-11 70 views
1

我的佈局是這樣的:如何讓我的佈局具有相同高度的TableRows?

<ScrollView 
     android:id="@+id/scrollView_page1" 
     android:layout_width="300dp" 
     android:layout_height="700dp" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TableRow 
       android:layout_width="fill_parent" 
       android:layout_height="60dip" 
       android:gravity="right" 
        > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/string1" 
       android:id="@+id/textview1"/> 
      <EditText 
       android:id="@+id/edittext1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:width="200dp" 
       android:inputType="number"/> 
      </TableRow> 

      <TableRow 
       android:layout_width="fill_parent" 
       android:layout_height="60dip" 
       android:gravity="right" 

       > 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/string2" 
        android:id="@+id/textview2"/> 

      <Spinner 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/spinner1" 
        android:width="200dp" 
        /> 
       ......... 

TableRows之間的距離顯得不是那麼正規:有些人太接近,其中一些是太遠。我不想用android:paddingTop一一調整它們。

是否有任何簡單的方法可以使它們之間的距離相同?目前,它看起來像這樣:

Picture of layout as it is now with varying row heights

+0

這是我的佈局圖片 - > [http://imm.io/1bWnk](http://imm.io/1bWnk) –

回答

3

@giga_abhi是現貨,但我想補充一點,在每個的TableRow,您還需要:

android:layout_height="0dip" 

,並在LinearLayout

android:layout_height="fill_parent" 

,並在ScrollView

android:fillViewport="true" 
+0

任何關於這個問題的想法? :http://stackoverflow.com/questions/23087668/how-do-i-wrap-a-second-text-around-first-text-title-both-are-in-text-view –

+0

@JusticeBauer我已經有一個去,但它不完全優雅! –

1

LinearLayout集:

android:weightSum="(no of tables say 3)"` 

,並在每個TableRow加入這一行:

android:layout_weight="1"` 

這將形成的TableRow以相同的高度你的方向是垂直的。唯一的部分仍然是調整TableRow內部元素的高度。

相關問題