Android TableLayout Wrap Text issues - android

My tablelayout displays a bunch of values that are random and is created programatically.
The issue I am having is that because I don't know the content that'll be displayed on the table I am not able to use setColumnShrinkable(index, true) and therefore since the table is big, some of the columns would get cut off and not show.
I've tried playing with mTableLayout.setShrinkAllColumns(true); but that would result in columns that shouldn't shrink to shrink and thereby making the wrapping of the texts formatted poorly (see image below) and also the height of each column is too large.
I've also tried playing with minWidth of the columns but that doesn't seem to be doing anything.
What would be the best wayt to tackle this issue? Thanks!

Related

Android Tablelayout - How to NOT make it fill the parents width?

I'm having some views that display several tables with data. So far so good.
The problem is, the only two ways I can find to size these views is either with a fixed width, which is not what I'm after because the length of the table entries can vary somewhat.
The other is to not specify a width, in which case the table just fills the parent's width by default. Which is also not what I'm after, because then the tables become difficult to read in landscape mode, when the cells become much wider than their content.
All I want is a table that is as wide as it needs to be based on its content, but not wider (and then I'll have to get it centered, but I think I can figure that one out... then again, that's what I always think before finding my head bumping into a simple problem that I thought should be trivial to solve...)
Is there a way to do this, or do I have to write my own table class for that?

Need advice on view layout for Google Glass app - a table with varying # rows which should fill the screen (dynamic text size)

I'm creating a Google Glass app and need to display a simple table. The table will have 2 columns and a varying # of rows.
I'd like the text size to be dynamic based on how many rows are in use. So if you have just 3 rows and the strings in the cells are short (in terms of length) the text size should be larger. If, on the other hand the view updates and now there are 6 rows and/or the string length in the cells is greater, the text size should be reduced.
Plainly put, the text size should be computed so that the text is as large as possible while still fitting the entire table on screen.
Any advice on how to create a layout to achieve this? I found the GridLayout but I think I'll need to dnyamically update it since the # rows can vary. Then there's the text size issue.
This is the kind of problem that is easy on the Web but hard on Android. So one approach might be to put a webview into your app and show an HTML table you generate locally and inject into the webview.
You might have reasons this won't work for you. If you need a more native approach this is a problem that has been solved in native Android apps, basically by measuring the font size to see if it will fit in a space iteratively. You start small and increase the size until it doesn't fit, then use the size before the one that didn't fit.
Here is a thread about that approach:
How to adjust text font size to fit textview
That will adress the difficult issue of text size.
Once that is solved the layouts are easy, many containers will work including GridLayout, TableLayout or even a series of nested LinearLayouts.

Table row wider than phone width

I have a TableRow with a decent amount of text in one of the columns. This text causes the table to be wider than the width of the phone, and so the right side of the data is cutoff.
I would like to wrap the text to the next row, but I can't tell how to do this. I tried setting singleLine="false", but that doesn't seem to do anything. Alternatively, I would be ok truncating the data, but there doesn't seem to be a great way of doing this either.
I ended up using a LinearLayout instead of a TableLayout. This does wordwrap by default and is close enough to TableLayout for my use.

Table layout only as wide as first image?

I'm building an Android app, and using a TableLayout ViewGroup to display my data.
I would like the TableView to occupy the entire width of the screen, however I'm having trouble getting this to work.
What seems to happen, is the table is only as wide as the widest element in the table, in this case, the image that I put in it.
Here's a screenshot to illustrate the problem.
Additionally, here's the XML source code of my layout.
What specifically should I do to have the layout stretch to the entire width of the screen?
Thanks in advance!
You only have 1 column. Therefore, it should be stretchColumns="0".
Creating a single-column TableLayout is pointless and wasteful. Use a vertical LinearLayout, please. You will probably find that it works better with respect to your problem as a side benefit.
Also, do not repeat the xmlns:android="http://schemas.android.com/apk/res/android" -- it only needs to go on the root element.
BTW, columns are indexed starting from 0, so you are stretching a non-existent column in your existing TableLayout.

Two columns of autowrapped text

I need to lay out several (for example, two) labels (textviews) as columns. The texts can be longer altogether than one screen line and may not contain line breaks, so they need to be formatted (wrapped) to fit the screen width.
I can arrange labels as columns if they are shorter altogether than a screen line. I can wrap a text to fit the screen if there’s only one column. But if the texts are longer and there are more than one column, I cannot achieve what I want, because the first column always fills the whole screen width.
I tried to do this via xml-markup. I tried a lot of markups using LinearLayout, TableLayout and RelativeLayout. All didn’t work. Maybe, I didn’t use them properly.
I can imagine the ways using code to manually calculate views’ widths, but haven’t tried. Any solution is welcome, but using markup only are preffered.

Categories

Resources