【问题标题】:Set Fixed Row Height in GridView在 GridView 中设置固定行高
【发布时间】:2013-08-04 10:06:18
【问题描述】:

我有想要在 GridView 中呈现的图像。这些图像的尺寸都相同 (250x250)。但是,我想在 GridView 中以 100x100 的方格显示它们。

<GridView 
        android:id="@+id/sectionListView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:numColumns="auto_fit" 
        android:verticalSpacing="10dp" 
        android:horizontalSpacing="10dp" 
        android:columnWidth="100dp" 
        android:stretchMode="none" 
        >

    </GridView >

以上是网格视图。我将 columnWidth 设置为 100。这实际上有效,但由于某种原因,高度始终为 120,在我的 250px 图像的顶部和底部留下水平黑条。不知何故,顶部和底部都有 10 个像素。更改垂直和水平间距无济于事,因为这会影响元素之间的间距。顶部和底部的这些黑条位于 gridView 项内。

【问题讨论】:

    标签: android android-gridview


    【解决方案1】:

    我会查看 ImageView,我假设您将在适配器中使用它来显示图像。您应该将 android:layout_width 和 android:layout_height 设置为 100dp,并确保 android:scaleType 设置为 centerCrop。

    【讨论】:

      【解决方案2】:

      在自定义适配器中

      view.setLayoutParams(new GridView.LayoutParams(GridView.AUTO_FIT, rowHigh));
      

      rowHigh 是你必须改变的维度

      【讨论】:

      • 本例中的v 是什么?
      • 我认为它代表视图
      【解决方案3】:

      如果您使用的是gridview,那么我认为您还使用另一个item_layout 来显示每个项目,我猜它是一个ImageView,因为您正在尝试显示图像。因此,您可以在该项目布局中将项目的大小限制为 100 x 100(即,在 item_layout 中 android:layout_width="100dp" android:layout_height="100dp"。)希望它有所帮助。

      【讨论】:

      • 我设置了 android:layout_width_height 并没有帮助。
      猜你喜欢
      • 1970-01-01
      • 2017-07-27
      • 2012-12-19
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多