How can I pre-ready the RecycledViewPool of RecyclerView to avoid initial jerks in scrolling?

Viewed 354

I've a RecyclerView with 3 different ViewTypes in it. If I scroll the list then for initial few items it shows a jerking/shivering during scroll. When RecycledViewPool is filled to max limit then as views are reused so scrolling becomes smooth. So, I was thinking of making the RecycledViewPool pre-ready. I tried creating some view holders and added in the pool before the user starts scrolling. But the pool shows 0 count for manual inserted views. It shows correct count when RecyclerView itself adds view to the pool on scroll. I'm using following method to achieve this. Is it good idea? or there is some more accurate solution for this?

   private void addDummyRecycledViews() {
                  int size = demoAdaptor.getList().size() > 7 ? 7 : demoAdaptor.getList().size();

                RecyclerView.RecycledViewPool recycledViewPool = recyclerView.getRecycledViewPool();
                for (int i = 0; i < size; i++) {
                    BaseViewHolder viewHolder = null;
                    int viewType = demoAdaptor.getItemViewType(i);
                    int recycledViewCount = recycledViewPool.getRecycledViewCount(viewType);
                    AppLogger.d("usm_test_adapter_dummy", "viewType= "+viewType+" ,recycledViewCount= "+recycledViewCount);
                    switch (viewType) {
                        case VIEW_TYPE_SIMPLE:
                            AppLogger.d("usm_test_adapter_dummy", "generate VIEW_TYPE_SIMPLE");
                            viewHolder = demoAdaptor.createSimpleItemViewHolder(recyclerView);
                            break;
                        case VIEW_TYPE_SEARCH:
                            AppLogger.d("usm_test_adapter_dummy", "generate VIEW_TYPE_SEARCH");
                            viewHolder = demoAdaptor.createSearchItemViewHolder(recyclerView);
                            break;
                        case VIEW_TYPE_VIDEO:
                            AppLogger.d("usm_test_adapter_dummy", "generate VIEW_TYPE_VIDEO");
                            viewHolder = demoAdaptor.createVideoItemViewHolder(recyclerView);
                            break;
                    }
                    if (viewHolder != null) {
                        demoAdaptor.onBindViewHolder(viewHolder, i);
                        recycledViewPool.putRecycledView(viewHolder);
                    }

                }
                recyclerView.setRecycledViewPool(recycledViewPool);

        }
0 Answers
Related