1

我想实现这样的目标在此处输入图像描述

但我尝试了几种方法,通过调整图像视图的 layout_width、高度,它仍然给我不一致的单元格大小在此处输入图像描述

这是我的代码:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".STA" >

<android.support.v4.view.PagerTitleStrip
    android:id="@+id/pager_title_strip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="#33b5e5"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    android:textColor="#fff" />
</android.support.v4.view.ViewPager>

主要活动.xml

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/photogridview"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:columnWidth="90dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"></GridView>

fragment_st_dummy.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
    android:id="@+id/imgv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY" />

<TextView
    android:id="@+id/txtv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
 </LinearLayout>

customitemview.xml

我的问题是:

  1. 如果我想为描述面板设置一个固定高度,可以吗?
  2. 通过固定图像大小来实现gridview单元格大小的一致性是最佳实践吗?
4

1 回答 1

1

不幸的是,这是 GridView 的问题之一。如果项目的大小不同,您将遇到问题。简单的解决方案是将它们全部设为固定大小。您可以查看 StaggeredGridView。它有一个视图开源实现,但我自己没有尝试过,所以我无法评论它们。

于 2013-10-07T16:41:32.820 回答