0

I want my main menu be a GridView of icons - 6 icons to be specific.

When the phone is in the portrait layout i want them to be in 2 columns, when it is in horizontal layout - 3 columns --- have sorted that out.

What I didnt sort out is how to make them occupy merely the whole screen.

Fitting it to the screen width is not a problem - it is fitting it to the screen height that makes me stumble.

I want it to stretch/shrink my cells depending on the screen size. I have tried counting screen height and dividing it by 3 - but there are certain problems and I dont think that that is the most elegant solution.

So basically how do I occupy my screen (say in a portrait layout) with a gridview of two columns (3 rows) solely? Are there any xml attributes that could help me?

This is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"    
    android:gravity="center"
/>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Denys
  • 4,287
  • 8
  • 50
  • 80
  • 1
    "I want my main menu be a GridView of icons - 6 icons to be specific." -- why? Why not use nested `LinearLayouts`, or a `TableLayout`, where you have more control? Or, why not use a dashboard (http://stackoverflow.com/questions/2873568/android-dashboard-pattern)? Or, why not dump the "main menu" entirely, taking the user to one of your real activities right away, and using action bar items to allow the user to navigate to the other activities? – CommonsWare Sep 23 '12 at 23:14

2 Answers2

0

I suggest creating the two layouts in xml first, then during the onCreate method you can do the re-sizing of the rows and columns.

For example

if layout is portrait
    set column width = screen width / 2

else if layout is landscape
    set column width = screen width / 3
mrres1
  • 1,147
  • 6
  • 10
0

Android Dashboard Pattern the answer to my question is somewhere there. Basically I used nested ListViews

Community
  • 1
  • 1
Denys
  • 4,287
  • 8
  • 50
  • 80