GridView or TableLayout?

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

I ask myself what is the best way to code this layout. Basically I just need to know how to get seven columns with equal width.

Thanks in advance!

+6
source share
5 answers

If this is the equal width you want, you can go for linearLayout with children with equal weight. check 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> 
+4
source

TableLayout seems to be better because the number of columns will not change. With GridView you need to add adapters and more.

+3
source

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

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

 <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> 
+2
source

It is best to use gridview. Try the following:

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

try it.

0
source

Source: https://habr.com/ru/post/900015/


All Articles