6

Wireframe of my layout

I managed to design the layout using TableLayout. android:layout_span helped me on that.

The problem is I need some gap between Column1 and Column2. In either way Padding / Margin

I am not prefering program for this task. there must be a simple way to done this.

Is that possible to set using xml?

Update: I tried to set column child's padding It's not align the columns evenly.

Mahendran
  • 2,719
  • 5
  • 28
  • 50

4 Answers4

4

Try adding android:layout_marginRight="8dp" the View in the column to the left of the place where you want the gap to be for each row in layout XML. It worked for me.

Better yet, you could put the padding dimension in the values/dimens.xml file and reference the margin from there.

For example:

values/dimens.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 up even more and stop code duplication, you could make a style for column 1 then all you'd have to do is apply the style for each View in the first column. See here for more info.

Tim Kist
  • 1,164
  • 1
  • 14
  • 38
2

Try to use a TableLayout in your 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 be, of course, Hosted in a linearLayout

SolidSnake87
  • 343
  • 3
  • 12
  • I just used table layout. And I am success in design the layout. I just need to set padding for column. – Mahendran Jul 11 '12 at 15:03
  • You can do that by padding your TableRows. Here you can find a good example : http://www.mkyong.com/android/android-tablelayout-example/ – SolidSnake87 Jul 11 '12 at 15:12
  • I have already seen that. Its just setting padding to whole table row not between columns. Have you tried? – Mahendran Jul 11 '12 at 15:18
0

You can do empty columns and maybe fill it with some invisible content.

This solution is not the best and I am stil searching for a better one..

user2161301
  • 674
  • 9
  • 22
0

Try using android:background property in android along with android:margin and mention that values in dip. This will show each childview in different color acc to your specification and margin will help you to give space between views. Hope this will help