How to get rid of spaces in gridview

前端 未结 4 789
长发绾君心
长发绾君心 2021-02-04 10:05

This thing has been doing my head in for a little while now and I can\'t seem to be able to solve it.

I\'ve got a grid view, in which I display a few bitmaps. I add a pa

4条回答
  •  离开以前
    2021-02-04 10:41

    If not otherwise set, a GridView will override the layout you're imagining it should produce by stretching things in various ways. If you want to have full control of the layout by defining the column widths and the size of the grid items, then you have to make sure to set the GridView's stretchMode property to "none".

    
    
    

    Also, you are filling the parent with your GridView width. I think you should be wrapping the content for the width unless you want extra filling added. Where are you adding the 5dp padding? Around each bitmap or around the edge of the gridview? I don't see it.

    You should probably be filling the height though. (in the following some of the width and heights can probably be replaced by "wrap_content")

    So, for you

    
    
    

    Also, not sure if you need column spacing and width, which would be something like (or a dp instead of wrap_content) - you may not need these in your GridView - I'm not sure:

        android:columnWidth="YYYdp"
        android:horizontalSpacing="0dp"
    

    ImageViews with 5dp padding:

    
    
    

提交回复
热议问题