When I'm trying to do a neat table layout in android, and try to space the columns equally, all I get is this.
I cannot for the life of me equally space those columns out.
You are using wrong the android:stretchColumns attribute. As you can see in the documentation it is the zero-based index of the column to stretch. So you want to stretch the first column, you should use :
android:stretchColumns="0"
in yout TableLayout.
Related
I am having trouble controlling the size of the columns in my
GridView.
The first column is only 3-4 chars and the other 4 columns
are 5-8 chars.
For some reason, all the columns are the same width,
leaving a huge amount of spacing after the first column and wrapping
the text inside the others.
Is there a way, I can set the width of
individual columns in the grid view?
In an ideal world, gridview
would work like an html table, where the smaller columns are shrunk to
fit the data and larger columns expand as necessary.
Any ideas would
be helpful
I have a dynamic table layout in my Android app. Number of rows and cols may vary, but each "cell" should contain an image. What would be the proper way of populating my table with those images but scaling them so regardless of number of rows and cols they scale to perfectly fit the table and keep their aspect ration?
Why not use a Gridview for this, check the Android docs.
Hope I got you right.
Try setStretchAllColumns(true) to stretch all of your columns. So your columns fit on every number of columns.
I'm unsure as to what the differences between the two of them are and which I should use for my purpouses?
What I'm trying to do is create a custom virtual numpad with text inputs and that can dynamically change its contents to have a date picker.
So I need a layout system which supports many different sized cells inside it.
Which better suits my needs and what's the difference?
In my experience I had both GridLayout and TableLayout give me the same results. They both seem to stretch the columns to fit the widest child element. Neither will give you gird lines or borders around the cells.
From the official docs on GridLayout:
Row and Column Specs
Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells. Although cells do not normally overlap in a GridLayout, GridLayout does not prevent children being defined to occupy the same cell or group of cells. In this case however, there is no guarantee that children will not themselves overlap after the layout operation completes.
and from the TableLayout:
The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.
So it seems to me that the GridLayout is a bit more versatile and probably what you are looking for.
So I have a table layout that Im adding rows to through code since its not a constant table or a constant amount of rows. The problem Im having is right now my last column isnt fitting all the text because the middle row is set to stretch and its taking up most the view. Is there a way to set weights for the columns so that I can have the one row be bigger than the rest but still show everything else.
The problem Im having is right now my last column isnt fitting all the text because the middle row is set to stretch and its taking up most the view.
Then either change it so the last column is the stretch column, or list both (e.g., android:stretchColumns="1,2").
Is there a way to set weights for the columns so that I can have the one row be bigger than the rest but still show everything else.
By listing more than one in android:stretchColumns, the stretching effect is applied equally to all. You can think of this as the columns having equal weight.
I guess I just havent found a good explanation here. So can anyone please tell me what android:stretchColumns actually does? I have it in my table and have tried several different values but cannot seem to figure out what it is doing.
Sorry for the dumb question!
A TableLayout can specify certain columns as shrinkable or stretchable
by calling setColumnShrinkable() or
setColumnStretchable(). If marked as
shrinkable, the column width can be
shrunk to fit the table into its
parent object. If marked as
stretchable, it can expand in width to
fit any extra space. The total width
of the table is defined by its parent
container.
Have a look here, keep in mind that if your table fits nicely ( no space left to stretch) in the parent object, you would not see any changes no matter what value you put in.