如何缩小GridView项目之间的差距?

时间:2016-03-20 04:09:56

标签: android gridview

示例Captcha:

Example Captcha

以下是适配器的代码:

public View getView(int position, View convertView, ViewGroup parent) {
     ImageView imageView=new ImageView(context);
     imageView.setImageBitmap(list.get(position).getBitmap());
     imageView.setLayoutParams(new AbsListView.LayoutParams(
     (int) (parent.getWidth() / DataUtils.num),//DataUtils.num=3
     (int) (parent.getHeight() / DataUtils.num)));
     return imageView;
}

GridView的XML:

<GridView
    android:id="@+id/gv_paly"
    android:layout_below="@id/ll_top"
    android:layout_above="@id/ll_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
></GridView>

请问,如何减少CAPTCHA图像之间的差距,使其更专业?

1 个答案:

答案 0 :(得分:1)

使用android:stretchMode和android:horizo​​ntalSpacing。 这将在视图之间产生修复差距。您可以将其设置为0。

&B::RunThis

enter image description here

<GridView
    android:stretchMode="columnWidth"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="10dp"
    android:id="@+id/gv_paly"
    android:layout_below="@id/ll_top"
    android:layout_above="@id/ll_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</GridView>