获取按钮和gridview的麻烦

时间:2010-08-22 15:06:40

标签: android gridview

我有一个由多个按钮充气的网格视图。我只使用了gridview,它工作得很好。网格的顺序正确并且居中。虽然,我想在按钮网格下面添加一个不同且居中的按钮。为此,我决定切断gridview,然后添加按钮(因此它不会受到gridview的影响)。我尝试使用以下代码来分隔视图:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TableLayout 
    android:id="@+id/tbl_gridcreator"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center">
    <TableRow>
        <GridView
            android:id="@+id/gridview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="150px"
            android:numColumns="7"
            android:stretchMode="spacingWidthUniform"
            android:gravity="center">
            <!-- 
            android:horizontalSpacing="0px" -->

        </GridView>
    </TableRow>
    <TableRow android:gravity="center">
        <Button android:text="Submit" 
            android:id="@+id/submit" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
        </Button>
    </TableRow>
</TableLayout>
</LinearLayout>

问题在于,此代码将网格视图向左侧滑动,奇怪地将其翻转(位置0在右下角,最后一个按钮在左上方被推离屏幕)。下图显示了结果:

知道为什么它向左推并翻转?或者也许我怎么能只用Gridview底部的按钮?

1 个答案:

答案 0 :(得分:1)

我明白了。我不知道为什么我使用TableLayout来封装GridViewButton,但我通过移除TableLayout并且只是拥有GridView来修复它Button中的RelativeLayout而不是LinearLayout。还有一些错误,但问题的大部分已经解决了。