Resize ImageView in recyclerview after Picasso.load ()?

I have:

  • recyclerview with GridLayoutManager
  • layout of a grid item with an ImageView in it (with a wrap_content height and a match_parent width) wrapped in a Framelayout, so the image below is center_horizontal aligned
  • Picasso downloads the image to the ImageView asynchronously from the internet.

Current situation: The image is being loaded into the imageView, but the image size is the image size in the reworked grid.

What I would like to achieve: After loading the image into the image, resize the image at runtime (redraw).

What I have tried:

  • notifyItemChanged () - could do the trick (at least in theory), but I can't check if the current view of the grid item is in the layout state, so my app crashed with IllegalStateException
  • listening to Picasso loading with callback and onSuccess () check the reverse aspect of the image view and try to resize the image itself with requestLayout (). Did not work. (Well, it worked, but only when it is an animation or something that causes the layout to redraw. If there is nothing, then the image is not redrawn.)
  • listening to Picasso loading with Callback and onSuccess () starts animation, animation of alpha image. This will cause redrawing. But sometimes it worked sometimes (and I don't know why).
+3


source to share


2 answers


What I did was set the ImageView to FrameLayout and then resize that FrameLayout to whatever you want. Hope this helps you.

<FrameLayout
        android:id="@+id/frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <ImageView
            android:id="@+id/video_thumbnail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:adjustViewBounds="true" />

</FrameLayout>

      



PS resizing FrameLayout:

viewHolder.frame.setMinimumWidth (neededWidth);

+4


source


Picasso has an image resizing function. Something like that:

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

      



You can change centerCrop to play with aspect ratio

0


source







All Articles