2014-07-07 29 views

回答

0

你不能用TableLayout這樣做,它們只支持列跨度。但你可以用GridLayout代替!嘗試是這樣的:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="2" 
    android:rowCount="2" 
    android:orientation="horizontal"> 

    <Button 
     android:layout_column="0" 
     android:layout_row="0" 
     android:layout_columnSpan="2" 
     android:layout_rowSpan="2" /> 

    ... 

</GridLayout> 

要確定有多少行和列有對GridLayout使用這兩個屬性:

  • android:columnCount
  • android:rowCount

你可以定義一個的位置的GridLayout與這兩個屬性裏面:

  • android:layout_column
  • android:layout_row

而且你可以定義多少行或列的View與這兩個屬性的跨越:

  • android:layout_rowSpan
  • android:layout_columnSpan

請注意,GridLayout僅與API級別14加入!如果您想在早期版本中使用GridLayout,則需要使用支持庫中的GridLayout

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    ...  

</android.support.v7.widget.GridLayout> 
相關問題