Android: Reduce space between columns in GridView

前端 未结 7 2018
情深已故
情深已故 2021-02-04 05:14

See attached screenshot where I am attempting to reduce the space between the columns in my GridView.

My main.xml is as follows:



        
7条回答
  •  半阙折子戏
    2021-02-04 05:36

    I was having similar issue of having slight horizontal spacing between the columns in few devices. ( I did not required any space. ) I was properly calculating the grid item width by dividing it with total width. I was getting this issue only on Lenovo devices.

    following code was in activity related to grid.

    int myRequestedColumnWidth = myGridViewContentMain.getRequestedColumnWidth();
    
    Point size = new Point();
    getWindowManager().getDefaultDisplay().getSize( size );
    int width = size.x;
    int height = size.y;
    
    int myGridColumns = width / myRequestedColumnWidth;
    
    if ( myGridColumns == 0 || myGridColumns == 1 )
        myGridColumns = 2;
    myColumnWidth = ( width / myGridColumns );
    
    myGridViewContentMain.setNumColumns(myGridColumns);
    

    following code was in layout xml for grid

    
    

    I was unable to solve issue after changing stretch mode values.

    But following value in layout xml for GridView did the trick.

        android:horizontalSpacing="0dp"
    

    I hope, someone like me may find this helpful.

    Regards.

提交回复
热议问题