主菜单使用GridView占据整个屏幕

时间:2012-09-23 22:53:07

标签: android android-layout android-gridview

我希望我的主菜单是一个GridView图标 - 6个图标是特定的。

当手机处于纵向布局时,我希望它们在2列中,当它处于水平布局时 - 3列---已将其排序。

我没有理解的是如何让它们只占据整个屏幕。

将它安装到屏幕宽度不是问题 - 它适合屏幕高度让我绊倒

我希望它根据屏幕尺寸拉伸/收缩我的细胞。我已经尝试计算屏幕高度并将其除以3 - 但是存在某些问题,我不认为这是最优雅的解决方案。

所以基本上我如何占用我的屏幕(比如画像布局),只有两列(3行)的网格视图?是否有任何xml属性可以帮助我?

这是我的xml文件:

<?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"
/>

2 个答案:

答案 0 :(得分:0)

我建议先在xml中创建两个布局,然后在onCreate方法中重新调整行和列的大小。

例如

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

else if layout is landscape
    set column width = screen width / 3

答案 1 :(得分:0)

Android Dashboard Pattern我的问题的答案就在那里。基本上我使用嵌套的ListView s