Reputation: 22038
I'm working on an app that retrieves news articles from the web and displays them. The article contains different parts, text parts, images etc. so what I'm doing is parsing the article, creating Views (TextView, ImageView etc) accordingingly and adding them to a LinearLayout.
Especially on a tablet in landscape mode, this doesnt look good, so first thing which comes to mind is makes it 2 columns.
My question is: is there a library or a good piece of code out there that can do some if the work that is entailed with that, like measuring the height if the views I have added, choosing a good place within the content from where to switch to the second column, take care that the right column doesn't get deeper than the left one etc?
Pic for explanation.
Upvotes: 1
Views: 67
Reputation: 7450
There is not such a library since it is just supported by android system, but not in the your way.
We use fragments and flexible layouts for different screen sizes, it simple and powerful.
Try to read the following page for details.
http://developer.android.com/guide/practices/tablets-and-handsets.html
Upvotes: 0
Reputation: 6940
Sorry, I misread your question, you're building the layout programatically. As seen in this answer you can get the window dimensions like this:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
You can then figure out a threshold that looks good to start using multiple columns and make your views percentages of those sizes you measure.
Upvotes: 1