private void SetUpRecyclerView(RecyclerView _recyclerView) { //Create our layout manager _recyclerView.AddItemDecoration(horizontalDecoration); _recyclerView.HasFixedSize = true; var layoutManager = new LinearLayoutManager(this); onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager); onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync; onScrollListener.OnHide += OnScrollListener_OnHide; onScrollListener.OnShow += OnScrollListener_OnShow; _recyclerView.AddOnScrollListener(onScrollListener); _recyclerView.SetLayoutManager(layoutManager); }
private void ChangeLayout(RecyclerView _recyclerView) { if (Adapter != null && Adapter.ItemCount > 0) { int scrollPosition = 0; LinearLayoutManager mLayoutManager; // If a layout manager has already been set, get current scroll position. if (_recyclerView.GetLayoutManager() != null) { scrollPosition = ((LinearLayoutManager)_recyclerView.GetLayoutManager()) .FindFirstCompletelyVisibleItemPosition(); } switch (mCurrentLayoutManagerType) { case MyEnum.ListView: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.Thumbnail; ChangeMenuIconToThumbnail(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; case MyEnum.Thumbnail: var mGridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false); mCurrentLayoutManagerType = MyEnum.GridView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mGridLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mGridLayoutManager); break; case MyEnum.GridView: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.ListView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; default: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.ListView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; } Adapter = new Product_Adapter(this, Adapter.Product, this); Adapter.SetLayoutManager(mCurrentLayoutManagerType); _recyclerView.SetAdapter(Adapter); _recyclerView.ScrollToPosition(scrollPosition); recyclerView.RemoveOnScrollListener(onScrollListener); onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync; onScrollListener.OnHide += OnScrollListener_OnHide; onScrollListener.OnShow += OnScrollListener_OnShow; recyclerView.AddOnScrollListener(onScrollListener); //Decorate Recyclerview if (mCurrentLayoutManagerType == MyEnum.GridView) { _recyclerView.AddItemDecoration(verticalDecoration); } else { _recyclerView.AddItemDecoration(verticalDecoration); } } }