如何在GridView中设置图像项的尺寸以填充空格

时间:2016-01-10 00:38:14

标签: android xml gridview imageview picasso

我希望根据屏幕尺寸使网格视图中的图像具有更大的尺寸,即使我使用包装内容到图像视图&使列数固定它也留空间,我下载Picasso的图像 我的代码:

gridview的

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <GridView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp"
        android:numColumns="2">
    </GridView>
</FrameLayout>

图片视图

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/posterImage"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">
</ImageView>

my grid view

what I want

1 个答案:

答案 0 :(得分:0)

尝试手动添加layout_heightlayout_width参数,而不是 wrap_content

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/posterImage"
    android:layout_height="370dp"
    android:layout_width="370dp">
</ImageView>

最佳做法是将dp边距放入dimen.xml文件中。

同样在gridView中,您应该更改match_parent而不是fill_parent;