2
我有两个部分(两个片段:第一个片段覆盖屏幕的60%,剩下的第二个片段)。在第一个片段中,我放置了gridview,在第二个片段中创建了tableLayout。在gridView中,我放置了36个ediText。在向下的桌面布局中,我设计了自定义键盘。由于我需要将十个edittext显示为完全适合第一个片段,因此禁用了gridview的垂直滚动条。尽管在纵向模式下它在模拟器上有些作用,但它不适用于横向模式。所以,我决定先得到片段的高度,那么有什么办法可以得到片段的高度和宽度。即使在获得这些措施之后,如何在模式更改时使我的edittext适合当前片段?尽管我搜索了资料,但找不到明确的解决方案。以下是我的代码。任何建议将不胜感激。提前致谢。如何使gridview元素适合没有滚动条的屏幕?
<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>
对不起,我有36个edittexts 。所以它很简单,并通过Adapter类实现了36个edittext。如果我使用表格布局或其他布局,它会使代码冗长。 – Kanth
为真。你可以尝试制作一个自定义的不可滚动的gridview。诀窍是修改onMeasure。看到这个问题的答案http://stackoverflow.com/questions/4523609/grid-of-images-inside-scrollview – njzk2
嗨,你能告诉我我的错误在哪里。正如你所建议的我已经创建了自定义的gridview。当我在我的活动类中添加以下代码时,应用程序显示“应用程序意外停止”。 gridView =(ExpandableHeightGridView)findViewById(R.id.myId); gridView.setAdapter(new TextAdapter(this)); – Kanth