GridLayout设置item的间距

安卓4.0以后增加了网格布局,比起之前的tablelayout,这个会更高效一些,关于具体的API之类的网上已经很多了,这里只对开发过程中遇到的一些问题作说明:设置item间距方式。

1、刚开始的实验,为item设置margin,没有作用

2、接着查看其实现发现问题:Gridlayout内部的组件不能直接设置LinearLayout.LayoutParams,否则除了控件大小,其他一概不收,Margin自然也就不生效了;于是改正:

LinearLayout.LayoutParamsll=newLinearLayout.LayoutParams(381,206);
GridLayout.LayoutParamsgl=newGridLayout.LayoutParams(ll);
gl.rightMargin=37;
gl.bottomMargin=37;
appTextView.setLayoutParams(gl);

问题解决!

你可能感兴趣的:(GridLayout设置item的间距)