Staggered View rows and columns are not changing

401 Views Asked by At

My Staggered view is implemented like this MyApp but it should look like this Demo And i'm not able to change the rows and columns If i'm changing columns its fine but if i change row more than 1, then i get invalidOrientation warning but app runs with blank Activity.

MainActivity.java

package com.techshiv.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {

private StaggeredGridLayoutManager staggeredGridLayoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);

    staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, 2);
    recyclerView.setLayoutManager(staggeredGridLayoutManager);

    List<ItemObjects> staggerdedList = getListItemData();

    SolventRecyclerViewAdapter rcAdapter = new SolventRecyclerViewAdapter(MainActivity.this , staggerdedList);
    recyclerView.setAdapter(rcAdapter);
}

private List<ItemObjects> getListItemData(){
    List<ItemObjects> listViewItems = new ArrayList<ItemObjects>();
    listViewItems.add(new ItemObjects("Alkane", R.drawable.one));
    listViewItems.add(new ItemObjects("Ethane", R.drawable.two));
    listViewItems.add(new ItemObjects("Alkyne", R.drawable.three));
    listViewItems.add(new ItemObjects("Benzene", R.drawable.four));
    listViewItems.add(new ItemObjects("Amide", R.drawable.one));
    listViewItems.add(new ItemObjects("Amino Acid", R.drawable.two));
    listViewItems.add(new ItemObjects("Phenol", R.drawable.three));
    listViewItems.add(new ItemObjects("Carbonxylic", R.drawable.four));
    listViewItems.add(new ItemObjects("Nitril", R.drawable.one));
    listViewItems.add(new ItemObjects("Ether", R.drawable.two));
    listViewItems.add(new ItemObjects("Ester", R.drawable.three));
    listViewItems.add(new ItemObjects("Alcohol", R.drawable.four));

    listViewItems.add(new ItemObjects("Ether", R.drawable.five));
    listViewItems.add(new ItemObjects("Ester", R.drawable.three));
    listViewItems.add(new ItemObjects("Alcohol", R.drawable.four));

    return listViewItems;
}
}
1

There are 1 best solutions below

0
On

it does not have a parameter for row , basically you are specify orientation considering it as row count use this:

StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);