I'm trying to fit a 20x20 table into a view using a programmatically built TableLayout. The setStretchAllColumns/setShrinkAllColumns methods work perfectly for squeezing all the columns in, but I haven't found a way to get all the rows in.
Is there a corresponding method for packing the rows in?
There aren't any setStretchAllColumns/setShrinkAllColumns for rows in a TableLayout. One thing that you could try(I haven't tested it) is to give your TableLayout a weigtSum of 20(with the method setWeightSum()) and then set the weight(the layout_weight attribute from a xml layout) of 1 for each of your 20 TableRows in the TableLayout.
Related
I am developing android application which generating results dynamically with table layout. Table rows are generating dynamically. Each table row contains two text views. but the results are not filling total screen.
How to fill total width of screen with two text views of table row.
pleas help me.
Make sure both your TableLayout and TableRow has
android:layout_width="match_parent"
Else please post both xml layout code
I have a TableLayout which is specified in the XML, to which I add TableRows programmatically. I have to add the rows this way because I do not know the structure of the table (i.e., number of columns, etc...) until run time.
Initially, I was having a problem with the table extending off the right end of the page when there was enough data in the rows. Now I am shrinking the final column, which wraps the text in that column and causes the table to be entirely visible. However, I now have a problem where the shunk column is "taller" than the other cells it the row, which looks ugly. Here is a screen shot:
Well, apparently I'm not allowed to post an image because I do not have "10 reputation points".
I'm not sure how to get my problem across without the image. If anyone has any suggestions, I'd appreciate that.
Here is the XML that defines the TableLayout:
<TableLayout
android:id="#+id/boilingPoint"
style="#style/PhysicalPropertyTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And here is the code snippet that get the table and specifies the column to shrink:
TableLayout layout = (TableLayout) findViewById(tableLayoutID);
layout.setColumnShrinkable(shrinkIndex, true);
What can I do so that the height of each cell in the row is the same as the tallest row?
Thanks in advance for any help.
I am trying to create a table row element where the first line contains a title followed by an ImageView that should be all of the way to the right. The TextView should fill the entire width of the phone except for the ImageView at the end.
The solution depends on some details of the circumstances.
If all the rows have the same format
If all the rows have the same column layout, then set android:stretchColumns="0" on the TableLayout. This will make the first column (index 0) stretch to fill any remaining space.
If the header has a different format from the remaining rows
If you have more columns or need a different column layout for the rest of the rows, then you need to do something different. I don't believe any single item can span multiple columns.
If only the positioning is important and you don't really need to span across multiple rows, you can use the android:layout_column attribute on each of the header items. The column number is 0-based, so the first column is 0. The Eclipse layout builder doesn't seem to present this attribute, but it will handle the attribute if you type it into the xml.
If you can't fit your elements inside the same columns the rest of the table uses, then the header doesn't belong in a TableRow. As suggested in another answer, you can use a RelativeLayout instead of the TableRow. Alternately, you could move the header outside of the table.
First, use a RelativeLayout for your row. Use the typical ImageView, give it an id, and use the XML attribute android:layout_alignParentRight="true". Next, use the TextView, use android:layout_toLeftOf="#id/myid" and make sure it's width is "fill_parent".
edit: code tags
guys
I am wondering about the lenght of a table row.
In my application, views are dynamically created and added to tablelayout...and it gives no problems.
However, if the length of row is longger than the width of screen(since too many views are contained on the row), I can't see some of views on screen.
Do you know how to check it in prior to actually display the row on screen?
Thanks for your help.
You can use the tableRow attributes and change the height and width of it dynamically
TableRow tableRow = findViewById(R.id.tableRow1);
tableRow.setMinimumHeight(minHeight);
tableRow.setMinimumWidth(minWidth);
tableRow.setWeightSum(weightSum);
On an Android layout, I'd like to have a set of rows, each with two TextViews. The leftmost column of TextViews should be right-aligned, just left of an imaginary centerline down the screen. The rightmost column should be left-aligned.
Examples of this can be seen at http://stuff.greenberg.org/ScopeCalc.htm
What's the best layout to use?
IMO, TableLayout would be a logical choice with appropriate use of colspan/rowspan.
You can also do this using LinearLayout, with the two sub-views of each row each getting 50% of the width.
Using GridLayout you can apply columnspan and rowspan properties to the views inside the grid.