Android stretchmode在gridview中不起作用
我已将gridview定义为3列:Android stretchmode在gridview中不起作用,android,android-gridview,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定义: <Linea
<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>
当我将scaleType=“fitXy”属性添加到ImageView时,这就是我得到的图片:
我希望宽度由列数定义,高度与宽度相关。我正在使用谷歌的教程[1]:。我可以通过将calculateInSampleSize方法的返回值更改为1来克服这个问题。这不是一个解决方案,因为这意味着我没有加载更小的图片。通过将scaleType设置为fitXY,您可以清楚地看到stretchMode可以工作 在第一个屏幕截图中,ImageView被拉伸,但图像是纵向的,因此您可以看到黑色空间
您可能需要将scaleType设置为centerCrop。否。这给了我与第二张截图相同的尺寸,只是它切下了部分屏幕pic@JY2k现在我得到了你想要的。我不确定它是否有效,但请尝试将android:adjustViewBounds=“true”属性添加到ImageView。它根本不会影响大小