增加android中的网格间距

Jam*_*mes 40 android

我有一个gridview,其中我有很多三个列的项目.我想增加它们之间的间距.我怎么能在android中做到这一点?

Par*_*ani 129

您可以在GridView标签中使用android:verticalSpacingandroid:horizontalSpacing根据您的要求提供间距.

例如:

  <GridView
        android:layout_height="wrap_content"
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:numColumns="auto_fit"
        android:horizontalSpacing="10dp"       // space between two items (horizontal)
        android:verticalSpacing="10dp">        // space between two rows (vertical)
  </GridView>
Run Code Online (Sandbox Code Playgroud)

  • @Ramswaroop使用填充,并在GridView`android:clipToPadding ="false"` (3认同)
  • @Ramswaroop您不能为此使用保证金吗? (2认同)