private void initGridLayout() { mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button); try { int screenOrientation = getResources().getConfiguration().orientation; if (!TextUtils.isEmpty(BrewSharedPrefs.getUserToken())) { userToken = BrewSharedPrefs.getUserToken(); } grid = (RecyclerView) findViewById(R.id.grid); grid.setItemAnimator(new DefaultItemAnimator()); grid.setHasFixedSize(false); int gridColumns = 3; if (screenOrientation == Configuration.ORIENTATION_LANDSCAPE) { gridColumns = 4; } final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(gridColumns, LinearLayoutManager.VERTICAL); layoutManager.scrollToPosition(0); grid.setLayoutManager(layoutManager); List<Image> placeHolder = new Vector<>(); adapter = new GridImagesRecycler(placeHolder, this); grid.setAdapter(adapter); load(); } catch (Exception e) { if (BuildConfig.DEBUG) { Log.e(Constants.LOG, e.getMessage()); } } }