Set layout_column and layout_row in GridLayout programmatically

*爱你&永不变心* 提交于 2019-11-27 23:37:49

The equivalent of layout_column and layout_row, as with all layout_... parameters, is to be found as a parameter of a subclass of LayoutParams.

In this case it's GridLayout.LayoutParams, and we use it like this (for a 2x2 grid with a subview in the final row and column, centred within the cell):

gridLayout.setColumnCount(2);
gridLayout.setRowCount(2);

gridLayout.addView(subview, new GridLayout.LayoutParams(
                              GridLayout.spec(1, GridLayout.CENTER),
                              GridLayout.spec(1, GridLayout.CENTER)));

You have to do something like this:

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