Android 如何在“回收器”视图中使用湿壁画预切2-3图像

Android 如何在“回收器”视图中使用湿壁画预切2-3图像,android,fresco,Android,Fresco,我使用下面的代码,使用Fresco在Recycler视图中加载图像。 当前,只要用户滚动到任何项目,图像加载就会启动,湿壁画加载图像并将其缓存,以备以后使用,下次从缓存加载图像时使用。是否有任何方法可以预缓存图像,以便即使是第一次也可以快速加载图像 public class ProductFeedsRecyclerAdapterV2 extends RecyclerView.Adapter<ProductFeedsRecyclerAdapterV2.ViewHolder> {

我使用下面的代码,使用Fresco在Recycler视图中加载图像。 当前,只要用户滚动到任何项目,图像加载就会启动,湿壁画加载图像并将其缓存,以备以后使用,下次从缓存加载图像时使用。是否有任何方法可以预缓存图像,以便即使是第一次也可以快速加载图像

public class ProductFeedsRecyclerAdapterV2 extends RecyclerView.Adapter<ProductFeedsRecyclerAdapterV2.ViewHolder> {

    private static final String TAG = ProductFeedsRecyclerAdapterV2.class.getSimpleName();
    private List<ProductFeed> mItems;
    private float ratio;

    Context context;
    String user_id;

    public ProductFeedsRecyclerAdapterV2(Context context, List<ProductFeed> items) {
        mItems = items;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item_brand_feed, viewGroup, false);

        return new ViewHolder(v);
    }


    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int i) {

        final ProductFeed feed = mItems.get(i);

        CircleProgressBarDrawable drawable = new CircleProgressBarDrawable();
        drawable.setBackgroundColor(context.getResources().getColor(R.color.gray));
        drawable.setColor(context.getResources().getColor(R.color.colorAccent));

        GenericDraweeHierarchyBuilder builder =
                new GenericDraweeHierarchyBuilder(context.getResources());
        GenericDraweeHierarchy hierarchy = builder
                .setFadeDuration(100)
                .setProgressBarImage(drawable)
                .build();

        hierarchy.setActualImageScaleType(ScalingUtils.ScaleType.FOCUS_CROP);
        hierarchy.setActualImageFocusPoint(new PointF(0.5f,0f));

        Uri uri = Uri.parse(feed.image);
        viewHolder.ivBrandImage.setImageURI(uri);
        viewHolder.ivBrandImage.setHierarchy(hierarchy);
        viewHolder.ivBrandImage.setAspectRatio(1.15f);

    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.ivBrandImage) SimpleDraweeView ivBrandImage;
        ViewHolder(View v) {
            super(v);
            ButterKnife.bind(this, v);
        }
    }

}
公共类ProductFeedsRecyclerAdapterV2扩展了RecyclerView.Adapter{
私有静态最终字符串标记=ProductFeedsRecyclerAdapterV2.class.getSimpleName();
私人名单;
私人股本流动比率;
语境;
字符串用户标识;
公共产品FeedsRecyclerAdapterV2(上下文、列表项){
mItems=项目;
this.context=上下文;
}
@凌驾
公共视图持有者onCreateViewHolder(视图组视图组,int i){
视图v=LayoutInflater.from(viewGroup.getContext()).flate(R.layout.list\u item\u brand\u提要,视图组,false);
返回新的视图持有者(v);
}
@凌驾
public void onBindViewHolder(最终ViewHolder ViewHolder,最终int i){
最终产品feed=mItems.get(i);
CircleProgressBarDrawable可绘制=新CircleProgressBarDrawable();
setBackgroundColor(context.getResources().getColor(R.color.gray));
setColor(context.getResources().getColor(R.color.colorAccent));
GenericDraweeHierarchyBuilder生成器=
新的GenericDraweeHierarchyBuilder(context.getResources());
GenericDraweeHierarchy层次结构=生成器
.setFadeDuration(100)
.setProgressBarImage(可绘制)
.build();
setImplementMageScaletype(ScalingUtils.ScaleType.FOCUS\u CROP);
setImplementImageFocusPoint(新的PointF(0.5f,0f));
Uri=Uri.parse(feed.image);
viewHolder.ivBrandImage.setImageURI(uri);
viewHolder.ivBrandImage.setHierarchy(层次结构);
viewHolder.ivBrandImage.setAspectRatio(1.15f);
}
@凌驾
public int getItemCount(){
返回mItems.size();
}
类ViewHolder扩展了RecyclerView.ViewHolder{
@BindView(R.id.ivBrandImage)SimpleDraweView ivBrandImage;
视图支架(视图v){
超级(五);
黄油刀。绑定(这个,v);
}
}
}

Fresco支持预取,请参见

你只要打个电话就可以了

imagePipeline.prefetchToDiskCache(imageRequest, callerContext);


预回迁到磁盘或位图缓存。

查看github页面,Fresco已经缓存位图。是的,当用户滚动到项目时,Fresco开始加载和缓存图像,因此第一次加载图像时会有延迟,因为此时图像是从服务器获取的,下次Fresco从缓存获取图像时也会有延迟。
imagePipeline.prefetchToBitmapCache(imageRequest, callerContext);