如何在没有滚动条的情况下使gridview元素适合屏幕?

时间:2012-09-04 09:48:33

标签: android gridview height android-edittext

我在一个屏幕上有两个部分(两个片段:第一个片段占据屏幕的60%,第二个占据剩余部分)。在第一个片段中我放置了gridview,在第二个片段中我创建了tableLayout。在gridView中我放置了36个ediTexts。在down tablelayout中,我设计了自定义键盘。因为我需要将十个edittexts显示为完全适合第一个片段,所以我禁用了gridview的垂直滚动条。即使它在纵向模式下在模拟器上有所作为,但它在横向上不起作用。所以,我决定首先获得片段的高度,所以有没有办法获得片段的高度和宽度。即使在获得度量之后,如何在模式更改时使我的edittexts适合当前片段?虽然我搜索过资料,却无法找到明确的解决方案。以下是我的代码。非常感谢任何建议。提前谢谢。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <FrameLayout
                android:id="@+id/fLayout1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:background="@drawable/background3">
        <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:columnWidth="18dp"
                android:numColumns="9"
                android:verticalSpacing="0dp"
                android:horizontalSpacing="5dp"
                android:stretchMode="columnWidth"
                android:gravity="center"
                android:listSelector="@null"/>
        </FrameLayout>

        <FrameLayout
                android:id="@+id/fLayout2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="4"
                android:background="@drawable/background2">

        <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/keypad"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:stretchColumns="*">

        <TableRow>
        <Button android:id="@+id/keypad_1"
        android:text="1"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_2"
        android:text="2"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_3"
        android:text="3"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_4"   
        android:text="4"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_5"
        android:text="5"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>



        <Button android:id="@+id/keypad_6"
        android:text="6"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_7"
        android:text="7"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_8"
        android:text="8"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_9"
        android:text="9"
        android:background="@drawable/custombutton"> 
        </Button>

        <Button android:id="@+id/keypad_10"
        android:text="C"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>
        <Button android:id="@+id/submit"
        android:text="validate"
        android:layout_span="5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/custombutton">

        </Button>
        </TableRow>
        </TableLayout>

        </FrameLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

gridView始终可滚动。您可以创建一个具有固定大小的自定义(有一个示例)

如果您知道您将拥有10个元素,请使用静态布局(例如使用tablelayout)