【问题标题】:How to decrease gap between items in griview如何减少gridview中项目之间的差距
【发布时间】:2017-10-29 18:01:45
【问题描述】:

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

我的代码是:Gridview

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

gridview 子代码:

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

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

这段代码的输出

【问题讨论】:

    标签: java android gridview imageview


    【解决方案1】:
    android:columnWidth="90dip"
    android:numColumns="auto_fit"
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多