My listview item consists of three columns and three rows.I used TableLayout for it.The space between columns was not uniform but i managed by setting margins.Now the layout looks perfect.
TableLayout is advantageous or
LinearLayout is depends on the application and layout you require.
Well, you can achieve everything by
LinearLayout, which you can get from
TableLayout as it
So, what’s the purpose of TableLayout?
Obviously, it gives more flexibility as you can arrange layout children into rows and columns. So, view looks more organize.
Achieving such things by
LinearLayout and its property like
weight, orientation, margin, padding etc. is really tiresome.
Second difference is the methods
setColumnShrinkable(), setColumnStretchable(), setColumnCollapsed() etc. introduce in
TableLayout. Look at Documentation.
Again, these methods help to organize view and you can span columns /cell, as you can in HTML.
Where TableLayout is useful compare to LinearLayout.
Consider a scenario when you want something like below: Full Detail Question
|img|leftText|rightText| ||(end of screen) |img|leftTextMedium|rightText| || |img|leftTextTooLongSoTrunc...|rightText||
rightText must always appear on screen next to
leftText no matter size of
leftText. You can’t achieve something just by
LinearLayout XML file (If you use weight property than it will add space between left and right text which is not desire output.)
You can achieve this easily by using
TableLayout (check accepted answer in about mention question) but for
LinearLayout you have to do some programming, XML won't works alone. Look here for code
I suppose you are now clear with the difference between above two
Keep in mind that performance wise
LinearLayoutis better because
TableLayoutrender more UI views and extends more methods. So, you should use
TableLayoutonly when you require Row-Column behavior.