vishal jangid vishal jangid - 25 days ago 5
Android Question

Android Grid view with different width of column

I am trying to make grid view with two column but the problem is that I want to change the width of every column randomly.

I try to create it using stagger grid view but it only change the height of column and I need to change of width of column.

I am adding image what I want to make below:

enter image description here

Answer
Please use setSpan method for gridlayoutmanager. In beginning use number of columns as 4, then as per need give span to each view in gridview. 

GridLayoutManager gridLayoutManager = new GridLayoutManager(activity, 4);

gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
{
    @Override
    public int getSpanSize(int position)
    {
        if (position == 0)
        {
          return 2;
        }
        else if(position == 1)
        {
          return 2;
        }
        else if(position == 2)
        {
        return 3;
        }
        else if(position == 3)
        {
        return 1;
        }                       
    }
 });