When I was working on my BF2Stats Android app, I had to find out how to place 2 widgets/layout elements on the same horizontal line, while keeping them stretched at the same time so they are filling the width of the screen.

It took me a little research before I found a solution, so I will share two methods with you today.

This tutorial will show you how to create layouts that stretches in the width.

In Eclipse I create a new Android Project by going to File -> New  -> Other -> Android -> Android Project. The default project just using the main.xml file for these example layouts will do just fine.

We can create a stretching layout with two different methods; Layout Weights and Layout Spans, I will show a simple example of both, and then I will show how to center an element in a TableLayout with Layout Spans.

More >