android grid view set column width - android

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

Related

Android images in table layout

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.

GridLayout vs TableLayout

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.

Android, grid, three equal width columns (33%) filled with images

I try to many times without success to create grid (image gallery) which look same on all devices. Usually easy task...seems that I here miss something. To rephrase question: grid columns must fill with of device screen, images must be resized to fit width and must retain proportion.
You can use a GridView and set the columns to 3 then assign you adapter as needed.
Another option is you use a LinearLayout for each row and assign the weight of each object to .33 of the total weight.

Android TableLayout Format

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.

Android ListView ellipsize wide column content

I have a ListView that shows 2 columns per row. I don't have any specific column layout XML so Android is determining it for me. If the text in the 1st column is too wide then bad things happen to the layout of the 2nd column. Ideally I want Android to ellipsize the text in the 1st column at a sensible width and/or restrict the 1st column's width to 80% of the total displayable width. Can I do this in code?
Am happy to ellipsize the column 1 text itself manually when setting up the ListView if that's simple but it would have to cope with orientation changes (because in landscape the column 1 text would not be so wide as to have to ellipsize).
Thanks.
Set the width of your textviews to a specific width, ie, 50dp instead of wrap_content.
Then set ellipsize to true.
The rest should take care of itself.

Categories

Resources