5

http://img683.imageshack.us/img683/645/weatherscreenmockupoutl.png

I am asking myself whats the best way to code this layout. Basicly i just need to know how to get seven columns with an equal width.

Thanks in advance!

kabuko
  • 36,028
  • 10
  • 80
  • 93
timoschloesser
  • 2,790
  • 4
  • 25
  • 33

5 Answers5

4

if it is the equal width that you want, you can go for linearLayout with children of equal weight. check out the following xml.

<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>
Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
3

TableLayout seems better, because the number of columns won't change. With GridView you have to add adapters and stuff.

Reno
  • 33,594
  • 11
  • 89
  • 102
2

You can make a good combination of TableLayout with TableRow, and make rows and columns as you want, very easy.

This is an example with 2x2 grid with 4 buttons (put insidea a LinearLayout for example):

<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>
Pelanes
  • 3,451
  • 1
  • 34
  • 32
0

The best is to use a gridview. Try someothing like this :

<GridView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:numColumns="7" />
lokoko
  • 5,785
  • 5
  • 35
  • 68
  • Seems like the obvious solution, but for static content I'd still go with LinearLayout. GridView needs an adapter to be populated. – timoschloesser Dec 18 '12 at 11:33
0
/>
<GridView 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="7"
android:stretchMode="columnWidth"
android:gravity="center"
/>

try this..

shunryui nik
  • 82
  • 1
  • 8