【发布时间】:2015-05-17 04:06:16
【问题描述】:
我是 Android 开发新手,正在制作我的第一个应用程序,它是一个项目的单词搜索应用程序,我正在使用 GridView 来显示搜索的字母。我可以使用布局 xml 更改网格中单元格的宽度,但是我无法更改高度,目前它太多了。
我尝试在 Google 上回答如何执行此操作,但我发现的所有内容都涉及在自定义 arrayAdapter 中覆盖 getView,并且我并没有真正遵循如何执行此操作或在执行此操作时如何将高度设置为固定量.我在布局文件中将行宽设置为 25dp,并希望更改高度以匹配该值,但我似乎无法在网上找到任何易于遵循的方法。
如果您能提供帮助,请提前欢呼。
编辑:这里是我填充网格的地方:
//fill GridView with the puzzle input array from the puzzle class
ArrayAdapter<String> gridAdapter = new ArrayAdapter<String>(c, R.layout.cell_layout, todaysPuzzle.puzzleInputArray);
wordsearchGrid.setAdapter(gridAdapter);
//fill ListView with the searchWords array from the puzzle class
ArrayAdapter<String> wordsAdapter = new ArrayAdapter<String>(c, R.layout.cell_layout, todaysPuzzle.searchWords);
wordsList.setAdapter(wordsAdapter);
这是 gridView 的布局(我使用了两个,一个用于 wordsearch,一个用于存储搜索词:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
tools:context="little.keith.wordsearch.TodaysActivity" >
<GridView
android:id="@+id/wordsearchGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="4dp"
android:background="@android:color/black"
android:columnWidth="25dp"
android:gravity="top"
android:horizontalSpacing="2dp"
android:numColumns="12"
android:stretchMode="none"
android:verticalSpacing="2dp" >
</GridView>
<GridView
android:id="@+id/wordsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@android:color/black"
android:numColumns="auto_fit"
android:layout_below="@+id/wordsearchGrid"
android:horizontalSpacing="2dp"
android:verticalSpacing="2dp"
android:layout_centerHorizontal="true" >
</GridView>
这里是 cell_layout.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:gravity="center"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingStart="1dp"
android:paddingEnd="1dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
【问题讨论】:
-
欢迎 JasperMoneyShot,您能否编辑您的问题并添加您用于 GridView 的布局 xml?这将使人们有机会看到您可能出错的地方并更容易提出建议。
-
你看过这个documentation吗?
-
CodeMonkey:好的,谢谢。久美穗:是的,我看过它,但不知道如何让它做我想做的事,当我尝试它时,拼图根本没有显示。