【发布时间】:2011-05-01 12:30:57
【问题描述】:
我的 Android 应用程序中有一个 GridView,其中包含许多 ImageView。我屏幕上的空间有限,我希望图像尽可能多地占用可用空间。不幸的是,GridView 总是在 ImageViews 的外边缘留下 5 个像素的空白屏幕空间(ImageViews 之间的空间设置为水平/垂直间距并且行为正确)。空白空间有点像 ImageViews 周围的边距,但我无法摆脱它。有谁知道是什么导致了这个“边界”以及我如何摆脱它(或者至少让它变小)?谢谢。
更新:我通过在我的 Adapter 类的 getView() 方法中扩展一个 .xml 文件来创建 ImageViews。这是我正在膨胀的 xml:
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FF00FF" />
我在我的布局 xml 文件中定义了 GridView,如下所示:
<GridView
android:id="@+id/mygrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/abutton"
android:layout_marginBottom="8dp"
android:numColumns="5" android:background="#FF0000"/>
这是问题的屏幕截图。我的 GridView 中的红色区域。紫色区域是我的 ImageViews。显示的图像是一个简单的蓝色矩形,中心是透明的。图像为 45x45 像素(但在我的应用程序中只有 30x30 像素 - 我稍后会担心)。紫色周围的红色边框是我要消除的。
【问题讨论】:
标签: android gridview imageview