Why are there extra pixels around my Android GridView?

岁酱吖の 提交于 2019-11-27 17:50:33

Thanks for the advice everyone, but it turns out the answer was somewhere that we didn't expect. The extra pixels were caused by the selector that was assigned to my GridView. I guess the default selector is a 9-patch image that has a 5 pixel border around it. When I created and assigned a 9-patch that had smaller borders (or no borders at all - just a normal .png file) the extra space in my GridView went away.

Did you try setting the padding on the ImageView and the horizontalSpacing and verticalSpacing on the GridView to 0?

Try setting the layout_height and layout_width of the image view to fill_parent.

iv.setLayoutParams(ViewGroup.LayoutParams(ViewGroup.MATCH_PARENT, ViewGroup.MATCH_PARENT));

will do it dynamically, I believe.

oren zvi

For me nothing helped except setting the android:columnWidth attribute in the xml (for example android:columnWidth="50dp" )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!