有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何减少griview中项目之间的间距

我想缩小每个项目之间的差距。我试图减少布局中的水平和垂直间距,但不起作用

我的代码是:Gridview

<GridView
    安卓:id="@安卓:id/grid"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:columnWidth="90dip"
    安卓:numColumns="auto_fit"
    安卓:verticalSpacing="2dp"
    安卓:horizontalSpacing="2dp"
    安卓:dividerHeight="0.2dp"
    安卓:divider="#fff" />

gridview子代码:

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="90dip"
    安卓:layout_height="90dip" >

    <ImageView
        安卓:id="@+id/image"
        安卓:layout_width="90dip"
        安卓:layout_height="90dip"
        安卓:adjustViewBounds="true"
        安卓:contentDescription="@string/descr_image"
        安卓:scaleType="centerCrop" />
</RelativeLayout>

此代码的输出

Output of this code


共 (1) 个答案

  1. # 1 楼答案

    android:columnWidth="90dip"
    android:numColumns="auto_fit"
    

    这两条线造成了间隙。Gridview正试图在总屏幕宽度中的每一列90 dp宽度中容纳尽可能多的列。要减小间距,请更改列宽或指定固定的列数