0

我希望我的主菜单是图标的 GridView - 具体来说是 6 个图标。

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

我没有理清的是如何使它们仅占据整个屏幕。

适合屏幕宽度不是问题 -适合屏幕高度让我绊倒

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

所以基本上我如何用两列(3行)的gridview占据我的屏幕(比如纵向布局)?是否有任何 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"
/>
4

2 回答 2

0

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

例如

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

else if layout is landscape
    set column width = screen width / 3
于 2012-09-23T23:03:53.467 回答
0

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

于 2012-09-24T18:29:36.327 回答