Java Code Examples for androidx.recyclerview.widget.GridLayoutManager#scrollToPosition()

The following examples show how to use androidx.recyclerview.widget.GridLayoutManager#scrollToPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvancedListFragment.java    From YcShareElement with Apache License 2.0 5 votes vote down vote up
public void selectShareElement(ShareElementInfo shareElementInfo) {
    BaseData data = (BaseData) shareElementInfo.getData();
    for (int i = 0; i < mAdapter.getItemCount(); i++) {
        BaseListCell cell = mAdapter.getItem(i);
        if (cell.getData().equals(data)) {
            mTransitionCell = cell;
            GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
            layoutManager.scrollToPosition(i);
            return;
        }
    }

}
 
Example 2
Source File: MainFragment.java    From fresco with MIT License 5 votes vote down vote up
private void initializeGridRecyclerView(final View layout) {
  // Get RecyclerView
  mRecyclerView = UI.findViewById(layout, R.id.recycler_view);
  // Choose the LayoutManager
  GridLayoutManager layoutManager = new GridLayoutManager(getContext(), mConfig.gridSpanCount);
  layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  layoutManager.scrollToPosition(0);
  mRecyclerView.setLayoutManager(layoutManager);
}