Reputation: 5839
I want to stretch all columns in my grid layout equally , How can I do that ?
I am using this params for every cell
LayoutParams param2 =new LayoutParams();
param2.height = LayoutParams.WRAP_CONTENT;
param2.width = ViewGroup.LayoutParams.WRAP_CONTENT;
param2.setGravity(Gravity.CENTER);
param2.columnSpec = GridLayout.spec(i,FILL);
param2.rowSpec = GridLayout.spec(rowCount,FILL);
param2.setGravity(Gravity.FILL);
Upvotes: 1
Views: 255
Reputation: 12368
Setting width of child dynamically
GridLayout.LayoutParams params = (GridLayout.LayoutParams) child.getLayoutParams();
params.width = (parent.getWidth()/parent.getColumnCount()) -params.rightMargin - params.leftMargin;
child.setLayoutParams(params);
Upvotes: 1
Reputation: 1544
Build Your Own GridLayout using nested LinearLayouts so you can customize it like you want, Or simply set the weight for each cell you add but you will need set you minimum sdk to 21
Upvotes: 1