Note that there are some explanatory texts on larger screens.

plurals
  1. POFull-screen tabular layout
    text
    copied!<p>I have 12 basically identical views which I want to arrange in a grid that covers the whole screen. Depending on the device's orientation, I want to use a 3x4 or a 4x3 grid.</p> <p>As far as I understand, there are basically three approaches to this topic:</p> <ol> <li>Use a <code>GridView</code></li> <li>Use nested <code>LinearLayout</code> instances</li> <li>Use a <code>TableLayout</code></li> </ol> <p>I'd like to have a layout that</p> <ol> <li>automatically adapts to orientation changes (as <code>GridView</code> does)</li> <li>uses all available screen space (as nested <code>LinearLayout</code> instances do)</li> <li>doesn't allow scrolling (and without that "can't scroll any further" effect of the <code>GridView</code>)</li> <li>allows me to force the same size on all of my items</li> </ol> <p>By default, <code>GridView</code> has scrolling and doesn't fill the screen, whereas <code>LinearLayout</code> and <code>TableLayout</code> don't automatically adapt to orientation changes.</p> <p>Currently I'm using a <code>GridView</code> with <a href="https://stackoverflow.com/questions/4852867/how-to-disable-gridview-scrolling-in-android">disabled scrolling</a> and a <a href="https://stackoverflow.com/a/11101422/857390">custom adapter</a> which sets the item views' minimum height depending on the orientation and the container's height to force a filled screen. This works but feels like a really ugly hack.</p> <p>Dynamically constructing nested <code>LinearLayout</code> instances depending on the orientation would probably also work, although I haven't tried that.</p> <p>This seems to be a frequent goal (<a href="https://stackoverflow.com/questions/7067449/android-how-to-stretch-rows-in-the-gridview-to-fill-screen">1</a>, <a href="https://stackoverflow.com/questions/5690144/how-can-i-force-a-gridview-to-use-the-whole-screen-regardless-of-display-size?rq=1">2</a>, <a href="https://stackoverflow.com/questions/9310606/make-full-screen-grid-on-android">3</a>, <a href="https://stackoverflow.com/questions/8697681/android-gridview-adjusting-to-screen-size">4</a>), but all the suggested solutions are either as hackish as mine or don't satisfy some of my requirements.</p> <p>As I'm new to Android development I'm not sure whether I'm missing something.</p> <p><strong>What is the optimal way of implementing this?</strong></p> <p>I'm targeting API level 8 and above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload