我正在尝试构建一个GridView,其中所有单元格都具有相同的高度,但看起来GridView对每个单元格应用了不同的高度。我将layout_height设置为在单元格中膨胀的布局上的固定尺寸,如果我只是将其添加到静态活动中,则这会保持不变。但是,当我尝试在单元中膨胀它时,它似乎正在将布局调整到所需的最小空间。Android- GridView调整单元格内容大小
布局XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="295dp"
android:layout_height="350dp"
android:orientation="vertical"
android:background="@drawable/row_book_back" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
<ImageView
android:id="@+id/img_thumbnail"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:scaleType="center"
android:src="@drawable/sample_image" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</LinearLayout>
所以我有有效的页眉和页脚,并应在剩余空间为中心的图像。当我将它添加到单元格上时会发生什么情况,图像占用的空间会根据图像高度调整大小,而不是只将图像居中,整个布局最终会少于指定的350dp。
我对Android很新,所以这可能是一个微不足道的问题。我很欣赏任何输入:)
您可以尝试设置minHeight。或者因为你想达到固定的高度,你可以将高度设置为LinearLayout中的视图。真的取决于你的相对布局的复杂性。 – Lamorak 2015-03-19 12:58:08