开发者

Trouble with getting a button along with gridview

开发者 https://www.devze.com 2023-01-12 09:38 出处:网络
I have a gridview that is inflated by multiple buttons. I used just a gridview and it worked fine. The grid was in correct order and was centered. Although, I wanted to add a button below the grid of

I have a gridview that is inflated by multiple buttons. I used just a gridview and it worked fine. The grid was in correct order and was centered. Although, I wanted to add a button below the grid of buttons that was different and centered. To do this I decided to section off the gridview and then add the button (therefore it wouldn't be affected by the gridview). I tried the following code to seperate the views:

<?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"
          开发者_如何学JAVA  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>

The problem is that this code smushes the gridview to the left and oddly it flips it (Position 0 is ont he bottom right and the last button is on the top left pushed off screen). The following image shows what is the result:

Trouble with getting a button along with gridview

Any idea why its pushed to the left and flipped? Or maybe how I could have just the Gridview with the button on the bottom?


I figured it out. Not sure why I was using a TableLayout to encapsulate the GridView and the Button but I fixed it by removing the TableLayout and just having the the GridView above the Button in a RelativeLayout instead of a LinearLayout. There still some bugs but the most of the issue has been solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消