39

I am working on a booking engine android app like an airline booking system. To fetch the content of say all the available airlines specific to a passenger search, this is then displayed on the mobile's screen.

Which one, a table layout or a grid layout, will be effective considering screen loading time, system memory consumption, and additional features?

7 Answers 7

35

**EDIT: This line was correct when this answer was written, but no longer applies to 99.9%+ of all Android devices: There is no GridLayout in the Android API. **

(Note: As of API level 14, there finally is GridLayout; see the answers below. In addition, the V7 support library adds GridLayout support down to API 7. However, this answer's description of GridView is still accurate and very well stated.)

If you mean GridView, TableLayout and GridView are completely different things.

A GridView is basically like a ListView but whose items are arranged in a strict grid. It is attached to an Adapter, and retrieves views from the Adapter has the user scrolls through it. All elements in the grid must be the same size. The user can move a visible selector through each item -- the goal of a GridLayout is to display the data from an Adapter and let the user navigate and select each of the displayed items. The only difference from a ListView is that the items are put in a grid instead of in a vertical list.

TableLayout is just a layout manager, somewhat like a table in HTML. It does not itself do any scrolling; to have something that scrolls you must put the TableLayout in a ScrollView. This implies that all of the data you are displaying must be populated into the TableLayout up-front, so the ScrollView knows the total space it is to scroll in. It also does not directly give you per-"item" selection or interaction, because a TableLayout doesn't have items, it is just a layout manager.

You didn't actually give near enough useful information about what you are actually trying to do for anyone to recommend what to use. It depends a lot on what specifically you want.

I mean what will be useful in terms of "additional features"?!? Well what features are you looking for!

Anyway as a general rule, an Adapter-based view should be used for any situation where you have a significant amount of data that the user is scrolling view; these are a lot more efficient than having to create the entire view hierarchy up-front to display your data. They are also the only ones that automatically provide per-item selection and other such features. The primary view for this that applications use is ListView, though GridView can also be used.

3
22

Since android 4.0, there is such a thing as a GridLayout. GridLayout is always preferable to TableLayout. It provides all that you already have on TableLayout, and can replace other layouts too.

It seems quite cool, and it seems that Google wish it to be as popular as the LinearLayout (according to their videos of Android 4.0).


EDIT: if you have to show a lot of items, consider using RecyclerView with GridLayoutManager. This can help in terms of memory and CPU usage.

1
  • @ToolmakerSteve The question was about having a grid-layout view, but this wasn't available back then, so when it was available, I wrote that you can use it as a solution for his problem. Of course, if there are tons of items to show, a RecyclerView with GridLayoutManager would be more suitable (which was also added later). The TableLayout is something that almost never get used, due to its weird behavior and annoying usage. Jan 3, 2017 at 20:07
10

TableLayout configurations are normally straightforward to accommodate, as GridLayout supports both row and column spanning. TableRows can be removed, as they are not required by GridLayout. For the same UI, a GridLayout will generally be faster and take less memory than than a TableLayout.

TableLayout is supported on all android versions , while GridLayout requires level 11 (Android ICS 4.0 ) or higher , but it can be easily added through support librarry v7 to support level 7( Android 2.1) or higher

4

This is a nice presentation of GridLayout which also outlines the differences in comparison to TableLayout: http://blog.stylingandroid.com/archives/669

One of the most important differences however is that it is only available in ICS (Ice Cream Sandwich) and newer. This currently means less than 30% of market share so for most developers the answer would be: wait a few years before you use GridLayout. YMMV of course.

4
  • 2
    It was added to the V7 support library. Aug 22, 2013 at 19:30
  • 1
    The link blog.stylingandroid.com/archives/669 is broken. @johndodo if you know the updated link, an edit would be appreciated. Aug 2, 2015 at 7:37
  • 1
    I have changed the link to web archive. Note that you can do the same by yourself, thanks for pointing it out though.
    – johndodo
    Aug 20, 2015 at 7:29
  • 2016 UPDATE: Because GridLayout is part of V7 support library, any Android 2.1 or later works with this (if using the support library). That is now 99.9% of all Android devices. Dec 27, 2016 at 21:55
2

I think GridView should work better because as it is implemented with view recycling and stuffs as inherited from AbsListView. GridView is more difficult to deploy because you have to use with Adapter but it will work effciently if you have a lot of heavy views to load such as images

0

In grid layouts, the components can automatically set to the view by taking numcolumns="autofit". Here we don't have need to set how much rows & columns we required, but in table layout, there we haven't such kind of option & we have to set how many rows & columns we required. In table layout, we can't insert more than 1 item in a row without using relative layout

-3

I think a TableLayout would be more easy to use. For a GridLayout you need to build custom adapters and so one which result in a more complicated application.

Looking at different sceensizes, a GridLayout will choose a good number of columns and rows by itself according to the content and it will be more flexible with adding items.

Also the GridLayout will be more flexible but it is some more work to make.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.