Trả lời

4

nếu chiều rộng bằng nhau mà bạn muốn, bạn có thể đi cho linearLayout với trẻ có trọng lượng bằng nhau. hãy xem xml sau.

<LinearLayout 
    layout:orientation="horizontal" 
> 
    <LinearLayout 
     android:id = "@+id/firstcolumn" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_width="0dp" 
    > 
    // do the same for your rest of the six children 

</LinearLayout> 
3

TableLayout có vẻ tốt hơn, vì số cột sẽ không thay đổi. Với GridView bạn phải thêm bộ điều hợp và nội dung.

2

Bạn có thể tạo sự kết hợp tốt của TableLayout với TableRow và tạo hàng và cột tùy thích, rất dễ dàng.

Đây là một ví dụ với lưới 2x2 với 4 nút (đặt insidea một LinearLayout ví dụ):

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

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

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

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

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

     <Button 
      android:id="@+id/button4" 
      android:layout_weight="1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
    </TableRow> 
</TableLayout> 
0

Điều tốt nhất là sử dụng một GridView. Hãy thử someothing như thế này:

<GridView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:numColumns="7" /> 
+0

Có vẻ như giải pháp rõ ràng, nhưng đối với nội dung tĩnh tôi vẫn muốn đi với LinearLayout. GridView cần một bộ điều hợp để được phổ biến. – timoschloesser

0
/> 
<GridView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:columnWidth="90dp" 
android:numColumns="7" 
android:stretchMode="columnWidth" 
android:gravity="center" 
/> 

thử này ..