title: best practice to picasso fetch with match parent in android
body: <p>I'm using Picasso to download pictures and show them in a RecyclerView. I'm trying to prevent the small delay which is happening when I'm scrolling the RecyclerView and Picasso is downloading the new pictures, so I'm using fetch. When I was using exact size for the pictures, it worked well, but now I'm using "match parent" (to work on all devices) in my xml, and since then there is a delay and when I'm scrolling back and forth, it doesn't remember the pictures (delay on the pictures that has been already seen).
  I tried just fit() and centerCrop() but it was slow, so this is my current try of solving the issue:</p>
  
  <p>in the adapter (this runs only once) I set a listener to get the exact size of the ImageViews</p>
  
  <pre><code>private void preloadImage(final View picture) {
      ViewTreeObserver observer = picture.getViewTreeObserver();
      observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
              PictureUtil.fetchImage(picture.getHeight(), picture.getWidth());
              ViewTreeObserver mObserver = picture.getViewTreeObserver();
              mObserver.removeOnGlobalLayoutListener(this);
          }
      });
  }
  </code></pre>
  
  <p>In the PictureUtil I fetch all the pictures:</p>
  
  <pre><code>   public static void fetchImage(int height, int width) {
      if (height &gt; 0 &amp;&amp; width &gt; 0) {
          for (House house : Houses.houseList) {
              Picasso.get().load(getFrontPicturePath(house.id))
                      .resize(width, height)
                      .centerCrop()
                      .fetch();
          }
      }
  }
  </code></pre>
  
  <p>and in the adapter again this is how I load them:</p>
  
  <pre><code>Picasso.get()
              .load(PictureUtil.getFrontPicturePath(houseId))
              .error(PictureUtil.getPlaceholderPath(context))
              .fit()
              .centerCrop()
              .into(view);
  </code></pre>
  
  <p>and this is the imageview in the xml:</p>
  
  <pre><code>        &lt;ImageView
              android:id="@+id/house_row_picture"
              android:layout_width="match_parent"
              android:layout_height="170dp"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              tools:src="@drawable/img_small" /&gt;
  </code></pre>
  
  <p>So the problem again that I got delay on the images (not like when I had fix sizes) and when I'm scrolling in the Recyclerview the images disappear and load again. What am I doing wrong? Is there a best practice for this?</p>
  
  <p>Thanks in advance</p>