简体   繁体   中英

With RecyclerView, is Picasso still necessary?

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 (ie, last week)

Any findings on this? Cheers

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.

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 <simon@demondevelopers.com>
 * 
 */
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);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM