如何在RecyclerView Android onBinding中预装图像?

时间:2016-04-01 13:21:35

标签: android load android-recyclerview image-loading

  

将图像加载到recyclerview非常慢,并且总是从在线加载。

private void setBackground(String imageUrl, ImageView background, boolean croped) {
    Picasso.with(contexts).setIndicatorsEnabled(false);
    if (croped)
        Picasso.with(contexts)
                .load(BitmapUrlHelper.getPictureUrl(contexts, imageUrl, 80)).centerInside().resize(((displayWidth) - 10), (Integer) ((displayHigh) / 5)).placeholder(R.drawable.cart)
            .into(background);
}
  

如果我绑定图像,则不会从cach加载

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Product product = Products.get(position);
    if (position < Products.size() - 2 ){
        Picasso.with(contexts).load(BitmapUrlHelper.getPictureUrl(contexts, Products.get(position + 1).getImage(), 80)).fetch();
    }

    if (position > 0 ){
        Picasso.with(contexts).load(BitmapUrlHelper.getPictureUrl(contexts, Products.get(position - 1).getImage(), 80)) .fetch();
    }


    if (product.getImage_preview_android() == null){
       setBackground(product.getImage(), holder.background_view, true);
  

布局部分

 <uk.co.senab.bitmapcache.CacheableImageView
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:scaleType="centerCrop"
        tools:src="@drawable/main_background"

        android:layout_gravity="right" />

0 个答案:

没有答案