With RecyclerView, is Picasso still necessary?
Asked Answered
L

2

5

Moving over form iOS recently, I realised that to handle fast scrolling of 100s of large images,

it's quite a bit of work and in practice you need to use Picasso (or maybe Volley).

Now that RecyclerView is here - has anyone implemented scrolling of many of large images, using RecyclerView ?

If so, do you have to use Picasso like in the old days (i.e, last week)

Any findings on this? Cheers

Lycurgus answered 28/6, 2014 at 20:30 Comment(2)
Considering that RecyclerView has been available for ~48 hours and cannot be used by most developers at the present time (it's only in AAR format), you will find few people who have used it. Moreover, RecyclerView does not download images asynchronously and prepare them for use, which is what Picasso does. What specifically are you expecting RecyclerView to do that would eliminate the need for Picasso?Adriannaadrianne
Hi CW ... "Moreover, RecyclerView does not download images asynchronously and prepare them for use" ... you know, that's just what I was asking really: as I understand it, RecyclerView is Android improving list view, so that we can get smoother scrolling of large lists of large images, "more like on iOS". I was wondering if the whole point of it was it recycled images (if all it does is let you strip back the cell and load it again - that's a bit of a yawn). So, I want to know how this new R.V. affects our current typical workflow!Lycurgus
K
24

RecyclerView is nothing more than an improved, more modular and extensible version of the AbsListView class. It provides a better API for recycling Views, and provides a way to create all sorts of list views with the same API's - vertical, horizontal, grid, staggered grid, and so on. Loading images is not at all part of this API.

Therefore, loading images into it requires you to do exactly the same as you did before. For example, using Picasso:

@Override
public void onBindViewHolder(final MyViewHolder myViewHolder, final int i) {
    Picasso.withContext(mContext).load(myImageUrl).into(myViewHolder.imageView);
}

In fact, coming back to your point:

RecyclerView is Android improving list view, so that we can get smoother scrolling of large lists of large images

I highly doubt that performance will increase if you already implemented the ListAdapter the right way: using ViewHolder classes, and properly reuse the convertView. The RecyclerView ships these optimizations by default, so you don't have to anymore.

Kerin answered 29/6, 2014 at 9:20 Comment(5)
Ahhhhhhhhhhh! I highly doubt that performance will increase if you already implemented the ListAdapter the right way ...fascinating, Niek, thank you! You've hit the nail on the head. In a way, that's what I was really trying to ask, I think. "Is the new RecyclerView just a formalisation of the 'best way' to do list views that everyone already has to use, or is it something else again..." Thank you!Lycurgus
Indeed. They may have done some optimizations under the hood, which might improve performance a bit, but I think that's less significant then the optimizations ViewHolder and reusing the convertView provides. It is a new class written from scratch, after all.Kerin
if this is the correct answer, you should mark is the correct answer.Camembert
In this case, will Picasso take care of cancelling requests as in case of earlier ListView adapters? Or should we take care of it in onViewRecycled(ViewHolder holder)?Baun
@Joe I thought my list and gridviews were implemented "the right way" but the recyclerviews still improved my performance a lot.Brachycephalic
B
0

Yes its still needed as previous comments have mentioned but this also helps.

import android.support.v7.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.scrolling.PicassoFlingScrollListener;


/**
 * Example Use:
 *     mRecyclerView.setOnScrollListener(new PicassoRecyclerViewScrollListener(mPicasso));
 * 
 * @author Simon Lightfoot <[email protected]>
 * 
 */
public static class PicassoRecyclerViewScrollListener implements RecyclerView.OnScrollListener
{
    private final PicassoFlingScrollListener    mListener;
    private final RecyclerView.OnScrollListener mDelegate;


    public PicassoRecyclerViewScrollListener(Picasso picasso)
    {
        this(picasso, null);
    }

    public PicassoRecyclerViewScrollListener(Picasso picasso, RecyclerView.OnScrollListener delegate)
    {
        mListener = new PicassoFlingScrollListener(picasso);
        mDelegate = delegate;
    }

    @Override
    public void onScrollStateChanged(int newState)
    {
        mListener.onScrollStateChanged(null, newState);
        if(mDelegate != null){
            mDelegate.onScrollStateChanged(newState);
        }
    }

    @Override
    public void onScrolled(int dx, int dy)
    {
        if(mDelegate != null){
            mDelegate.onScrolled(dx, dy);
        }
    }
}
Baldachin answered 24/7, 2014 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.