GridView or TableLayout?
Asked Answered
V

5

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!

Vauban answered 25/10, 2011 at 7:35 Comment(2)
Table layout will work fine....Cenis
Downvoted because: The Image in the Link is not accessable anymore so we cannot see what the original question is.Lola
S
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>
Shirtmaker answered 25/10, 2011 at 7:47 Comment(0)
W
3

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

Washday answered 25/10, 2011 at 7:43 Comment(0)
M
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>
Maine answered 3/4, 2012 at 11:12 Comment(0)
G
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" />
Grossularite answered 18/12, 2012 at 8:2 Comment(1)
Seems like the obvious solution, but for static content I'd still go with LinearLayout. GridView needs an adapter to be populated.Vauban
B
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..

Brendabrendan answered 23/12, 2014 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.