Skip to content Skip to sidebar Skip to footer

Android Table Layout - Simple Exmple

I want to place a simple, single, grid at the bottom of my screen. Here is a screen shot of the desired result simple grid I am looking for It would be cool if I could make the '

Solution 1:

You can take a look at this. So in your case, you can add the following at the end:

<TableLayout
    android:id="table"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"/>

In your code, you can then get the reference of the TableLayout, then inflate the row with three columns then add the rows to your TableLayout:

TableLayouttableLayout= (TableLayout) findViewById(R.id.table);

//TODO: inflate some rows

tableLayout.addView(row1);
tableLayout.addView(row2);

etc...

Your inflated row layout would look something like the following:

<TableRow><TextViewandroid:id="@+id/first"android:text="first"android:padding="3dip" /><TextViewandroid:id="@+id/second"android:text="second"android:gravity="center"android:padding="3dip" /><TextViewandroid:id="@+id/third"android:text="third"android:gravity="right"android:padding="3dip" /></TableRow>

You can give each textview an id, so that when you inflate each row, you can reference the textview to set your data.

I think another important thing to note is that, depending on your data or data size, you can consider using a RecyclerView with a GridLayoutManager to more efficiently achieve what you're trying to do.

Post a Comment for "Android Table Layout - Simple Exmple"