How to remove the space between rows of grid view in android

前端 未结 8 997
猫巷女王i
猫巷女王i 2021-02-02 13:53

In android grid view there is extra space between the rows of grid view. I am not adding any space to the gridview.

here is my xml files

        

        
相关标签:
8条回答
  • 2021-02-02 14:07

    Just put last 2 lines in gridView

    <GridView
            android:numColumns="2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/gridView"
            android:horizontalSpacing="0dip"
            android:verticalSpacing="0dip"/>
    
    0 讨论(0)
  • 2021-02-02 14:08

    Put the following line in ur getView() method...

    mImage.setPadding(0, 0, 0, 0);
    

    I hope this will help you.

    0 讨论(0)
  • 2021-02-02 14:12

    It looks like your picture is being scaled to fit the column width of 50dp while maintaining the aspect ratio. This is introducing a bunch of unfilled space in the vertical layout. If you want your column to be 50dp wide, the easiest way to work out these spacing issues will be to adjust your imageview to have a width of 50dp and adjust the imageviews height proportional to that.

    0 讨论(0)
  • 2021-02-02 14:12

    I have another way as a fixing for the same issue while one using RecyclerView.

    Just pass the number of SpanCount like I have given 6 in GridLayoutManager(this, 6) and change the SpanCount to reduce or increase the gap between the items in the RecyclerView.

    Check this sample code-

    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 6);
      rvSizes.setLayoutManager(gridLayoutManager);
      SizeSelectorAdaptersizeChooserAdapter = new SizeSelectorAdapter(this, sizes);
      rvSizes.setAdapter(sizeChooserAdapter);
    

    Hope this will be useful. Thank you

    0 讨论(0)
  • 2021-02-02 14:14
    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:horizontalSpacing="5px"
        android:numColumns="3"
        android:columnWidth="50dip"
         android:verticalSpacing="0dip"
        android:gravity="center"/>
    
    <ImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/singlePhoto"
        android:layout_width="145dip"
        android:layout_height="145dip"
        android:scaleType="fitXY">
    </ImageView>
    
    0 讨论(0)
  • 2021-02-02 14:15

    just check that your "newsgridthumbpic" layout does not contain the extra padding or any background image having a large height that your grid view element.

    Also double check that you are supplying column_width as 50dip but your "imageview's" width is 145 dip.

    0 讨论(0)
提交回复
热议问题