florent37 / MaterialViewPager

A Material Design ViewPager easy to use library
https://www.fiches-plateau-moto.fr
Apache License 2.0
8.13k stars 1.48k forks source link

ScrollToPosition issue! #353

Open luifermoron opened 6 years ago

luifermoron commented 6 years ago

When I execute the next code, the image header is not fully loaded. ` final int position = 0; if (!(mRecyclerView.getLayoutManager() instanceof LinearLayoutManager)) return; LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); final int topItem = layoutManager.findFirstVisibleItemPosition(); final int distance = topItem - position; int maxScroll = 10; int anchorItem; if (distance > maxScroll) anchorItem = position + maxScroll; else if (distance < -maxScroll) anchorItem = position - maxScroll; else anchorItem = topItem; if (anchorItem != topItem) mRecyclerView.scrollToPosition(anchorItem);

            mRecyclerView.post(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.smoothScrollToPosition(position);
                }
            });`

12