0

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.

Nerdtron
  • 1,376
  • 16
  • 31
  • You should consider that making ever smaller will make it hard for your users. Presenting a large amount of information would, perhaps, be better handled with scrolling or some other mechanism. – ErstwhileIII May 04 '14 at 14:05

1 Answers1

0

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.

Community
  • 1
  • 1
Mark Scheel
  • 2,923
  • 1
  • 18
  • 23