Android 如何在没有滚动条的情况下使gridview元素适合屏幕?
我有两个部分两个片段:第一个片段占据了60%的屏幕,第二个片段占据了剩下的部分。在一个屏幕上。在第一个片段中我放置了gridview,在第二个片段中我创建了tableLayout。在gridView中,我放置了36个EditExt。在下表布局中,我设计了自定义键盘。由于我需要将十个EditText精确地显示在第一个片段上,因此我禁用了gridview的垂直滚动条。即使它在纵向模式下在emulator上工作,但在横向模式下不工作。所以,我决定先得到碎片的高度,有没有办法得到碎片的高度和宽度。即使在获得了度量之后,当模式发生变化时,如何使我的EditText适应当前片段?虽然我搜索了资源,但找不到明确的解决方案。以下是我的代码。如有任何建议,将不胜感激。提前谢谢Android 如何在没有滚动条的情况下使gridview元素适合屏幕?,android,gridview,height,android-edittext,Android,Gridview,Height,Android Edittext,我有两个部分两个片段:第一个片段占据了60%的屏幕,第二个片段占据了剩下的部分。在一个屏幕上。在第一个片段中我放置了gridview,在第二个片段中我创建了tableLayout。在gridView中,我放置了36个EditExt。在下表布局中,我设计了自定义键盘。由于我需要将十个EditText精确地显示在第一个片段上,因此我禁用了gridview的垂直滚动条。即使它在纵向模式下在emulator上工作,但在横向模式下不工作。所以,我决定先得到碎片的高度,有没有办法得到碎片的高度和宽度。即使在
<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>
gridView始终是可滚动的。您可以创建一个具有固定大小的自定义文件,例如
如果您知道将有10个元素,请使用静态布局,例如使用tablelayout,gridView始终是可滚动的。您可以创建一个具有固定大小的自定义文件,例如
如果您知道将有10个元素,请使用静态布局,例如使用tablelayout对不起,我有36个EditText。因此,它很简单,并且使用Adapter类完成了36个EditText。如果使用表布局或其他布局,则会使代码变得冗长。true。您可以尝试创建一个自定义的不可滚动的gridview。诀窍是修改onMeasure。看这个问题的答案嗨,你能告诉我哪里出错了吗。正如您所建议的,我已经创建了自定义gridview。当我在活动类中添加以下代码时,应用程序显示应用程序意外停止。gridView=ExpandableHeightGridView findViewByIdR.id.myId;gridView.setAdapterNewTextAdapterThis;发布一个新问题,包括代码和完整的stacktraceSorry,我有36篇编辑文本。因此,它很简单,并且使用Adapter类完成了36个EditText。如果使用表布局或其他布局,则会使代码变得冗长。true。您可以尝试创建一个自定义的不可滚动的gridview。诀窍是修改onMeasure。看这个问题的答案嗨,你能告诉我哪里出错了吗。正如您所建议的,我已经创建了自定义gridview。当我在活动类中添加以下代码时,应用程序显示应用程序意外停止。gridView=ExpandableHeightGridView findViewByIdR.id.myId;gridView.setAdapterNewTextAdapterThis;用代码和完整的stacktrace发布一个新问题