How to set up table layout in Android. Adding columns to xml

Wireframe of my layout

I was able to create a layout using TableLayout . android:layout_span helped me with this.

The problem is that I need the gap between columns 1 and column2. Anyway Padding / Margin

I do not prefer the program for this task. There should be an easy way to do this.

Is it possible to install using xml?

Update: I tried to set the replenishment of the column column. It does not align the columns evenly.

+4
source share
4 answers

Try adding android:layout_marginRight="8dp" view in the column to the left of the place where you want the space for each line in the XML layout. It worked for me.

Even better, you can put the fill size in the values ​​/dimens.xml file and specify the margin from there.

For instance:

values ​​/ dens.xml

 <resources> <dimen name="column_1_right_margin">8dp</dimen> </resources> 

Layout / table.xml

 <TableLayout ... layout params> <TableRow> <TextView ... layout params android:layout_marginRight="@dimen/column_1_right_margin" /> <TextView ... layout params /> </TableRow> <TableRow> <TextView ... layout params android:layout_marginRight="@dimen/column_1_right_margin" /> <TextView ... layout params /> </TableRow> </TableLayout> 

To clear it even more and stop duplicating code, you can create a style for column 1, then all you need to do is apply a style for each View in the first column. See here for more details .

+4
source

Try using TableLayout in the xml layout, and then for each TableRow of your table layout you can specify the left or right margin using android: layout_marginRight and android: layout_marginLeft. Your TableLayout will, of course, be placed in linear mode.

+2
source

You can create empty columns and possibly fill it with invisible content.

This decision is not the best, and I try to find the best.

0
source

Try using the android: background property in android along with android: margin and specify the values ​​in dip. This will show that each child has a different color according to your specifications, and the margin will help you provide space between the views. Hope this helps

0
source

All Articles