Anuja Kothekar
Anuja Kothekar

Reputation: 2557

GridLayout LayoutParams - programmatically apply weight and span

I want to apply colspan and rowspan on GridLayout programmatically. I have searched a lot for same. I have some doubts:

  1. Is there any other way I can create GridLayout params programmatically??
  2. Can I create it using generateLayoutParams(AttributeSet attrs) method? If yes How should I do it. How can I create AttributeSet programmatically. Any help will be appreciated. Thanks in Advance!

Upvotes: 1

Views: 2634

Answers (1)

Dharvik shah
Dharvik shah

Reputation: 1989

if you have height and width and just want to create GridLayout params programmatically use this :

GridLayout.LayoutParams param =new GridLayout.LayoutParams();
param.height = LayoutParams.WRAP_CONTENT;
param.width = LayoutParams.WRAP_CONTENT;
layoutParams.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, item.getRowSpan());
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, item.getColumnSpan());

gridlayout.setLayoutParams(param);

Upvotes: 1

Related Questions