@Override public void onClick(View v) { updateLayoutManager(new StaggeredGridLayoutManager( 3, StaggeredGridLayoutManager.VERTICAL)); } });
/** * @return The {@link StaggeredGridLayoutManager} object for a given context. * * @param count The no. of rows or columns count according to the orientation. * @param orientation The orientation of the layout manager. * {@link StaggeredGridLayoutManager#VERTICAL} or * {@link StaggeredGridLayoutManager#HORIZONTAL} */ public static StaggeredGridLayoutManager getStaggeredGridLayoutManager( int count, int orientation) { return new StaggeredGridLayoutManager(count, orientation); }
protected RecyclerView.LayoutManager getLayoutManager() { return new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); }
private void setColumnLayout(int columnCount) { if (columnCount > 1) { setLayoutManager(new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL)); } else { setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); unbinder = ButterKnife.bind(this); PresenterAdapter<String> adapter = new PresenterAdapter<>(); list.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); list.setAdapter(adapter); adapter.setOnItemClickListener((item, rowView, position) -> toast(format("{0}. {1}", position, item))); for (int i = 0; i < 100; ++i) { adapter.add(createRandomImageUrl(), PhotoPresenter.class); adapter.add(createRandomImageUrl(), LabelPresenter.class); } // sorting // PresenterAdapter.sort(adapter); // sort if model doesn't implement Comparable // adapter.sortBy((o1, o2) -> o1.compareTo(o2)); // adapter.update(0, "https://raw.githubusercontent.com/kibotu/RecyclerViewPresenter/master/screenshot.png"); adapter.notifyDataSetChanged(); }
mInstallButton = view.findViewById(R.id.select_app_install_btn); mSelectFromExternal = view.findViewById(R.id.select_app_from_external); mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, OrientationHelper.VERTICAL)); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL); dividerItemDecoration.setDrawable(new ColorDrawable(0x1f000000));
private void initLaunchpad() { mLauncherView.setHasFixedSize(true); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL); mLauncherView.setLayoutManager(layoutManager); mLaunchpadAdapter = new LaunchpadAdapter(this); SmartRecyclerAdapter wrap = new SmartRecyclerAdapter(mLaunchpadAdapter); View footer = new View(this); footer.setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VUiKit.dpToPx(this, 60))); wrap.setFooterView(footer); mLauncherView.setAdapter(wrap); mLauncherView.addItemDecoration(new ItemOffsetDecoration(this, R.dimen.desktop_divider)); ItemTouchHelper touchHelper = new ItemTouchHelper(new LauncherTouchCallback()); touchHelper.attachToRecyclerView(mLauncherView); mLaunchpadAdapter.setAppClickListener((pos, data) -> { if (!data.isLoading()) { if (data instanceof AddAppButton) { onAddAppButtonClick(); } mLaunchpadAdapter.notifyItemChanged(pos); mPresenter.launchApp(data); finish(); } }); }