0

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

halfer
  • 19,824
  • 17
  • 99
  • 186
vishal jangid
  • 2,967
  • 16
  • 22

2 Answers2

2

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;
        }                       
    }
 });
CBeTJlu4ok
  • 1,072
  • 4
  • 18
  • 51
  • i want to only two column in one row, only the width of column will change – vishal jangid Sep 30 '16 at 09:55
  • Yeah you will have 2 columns only. Give each view span of 2, then two columns of equal width. GIve one view span of 1 and other view span of 3 then you will have two columns in the width ratio 1:3. I have edited my post with code. Check it and tell if it helps. – Anish Kumar Dubey Sep 30 '16 at 13:43
-2

Use two or more synchronized list view will do. By 'synchronized', I mean when you swipe horizontally, both list views move accordingly.

You might checkout this PinterestListView repo for reference.

enter image description here

The sole difference is that you change the orientation of the list view, from vertical to horizontal.

If you don't wish to support horizontal swipes/scrolls, use two linear layout embedded into a vertical layout, that is it!

David
  • 15,894
  • 22
  • 55
  • 66
  • in this case the height of the grid item is changed but i want the height of the grid fix only want width change. Please check my image first – vishal jangid Sep 30 '16 at 08:41
  • you should read the post carefully, you need to change the orientation. – David Sep 30 '16 at 08:44
  • in your case height of the column is change but i do not want to change it and i want to scroll vertical. – vishal jangid Sep 30 '16 at 08:47
  • you need look at the source code in github, and use it as a reference. I could not see any challenges, if you want to take a look at the source code. – David Sep 30 '16 at 11:10
  • we do not need to use this github library this functionality is already provided by Android RecyclerView StaggeredGridLayoutManager. but i am looking for another type – vishal jangid Sep 30 '16 at 11:30
  • you don't need to use that library at all. you never read the post! read it carefully pls. – David Sep 30 '16 at 11:31
  • "For reference", see this in the post? – David Sep 30 '16 at 11:31