3
votes

I have a RecyclerView that loads images from the server. When I scroll the scrolling is quite jerky. I am using glide to load images I feel that images are being loaded every time the recycler view is being scrolled. So could anyone please tell how to stop loading images onscroll...

Thanks..

2

2 Answers

4
votes

You're probably doing something odd, like resizing the view, when the image load completes. Make sure you're not triggering layout calls or doing other expensive things when images are loaded. It's almost always possible to get relatively smooth scrolling while still loading images with Glide.

That said, you can use pauseRequests() and resumeRequests() to stop/start image loading when the user starts/stops scrolling:

// Scrolling starts.
Glide.with(fragment).pauseRequests();
...
// Scrolling stops.
Glide.with(fragment).resumeRequests();
1
votes
Thread t = new Thread(new Runnable() {
    @Override
    public void run() {
        Recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    Glide.with(MainActivity.this).resumeRequests();
                }
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    Glide.with(MainActivity.this).pauseRequests();
                }
                super.onScrollStateChanged(recyclerView, newState);

            }
        });
    }
});
t.start();