拉伸模式在gridview中不起作用

时间:2014-05-04 16:24:19

标签: android android-gridview

我已将gridview定义为3列:

<GridView
    android:id="@+id/wallpaper_gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:numColumns="3"
    android:stretchMode="columnWidth"/>

每个项目都由此XML定义:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

  <ImageView
    android:id="@+id/wallpaper_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

image

当我添加scaleType =&#34; fitXy&#34;物业到ImageView这是我得到的图片: image2

我希望宽度由列数和高度定义为与宽度有关。我正在使用Google的教程[1]:http://developer.android.com/training/displaying-bitmaps/load-bitmap.html。我可以通过将calculateInSampleSize方法的返回值更改为1来解决此问题。这不是解决方案,因为这意味着我没有加载较小的图片。

1 个答案:

答案 0 :(得分:0)

通过将scaleType设置为fitXY,您可以清楚地看到stretchMode的工作原理。

在第一个屏幕截图中,ImageView被拉伸,但图像处于纵向方向,因此您可以看到黑色空格。

您可能想要的是将scaleType设置为centerCrop。