Satyam Thakur
Satyam Thakur

Reputation: 1

Resizing item cards according to ImageSize

I am developing this meme app that fetches some images of mmeme from an api and displays it in the items of a recyclerview. The images are of different sizes, I want cards of the item to dynamically resize themselves according to the size of the image, please let me know what are some options that I have to achieve this, also I am having a circular progress bar as a placeholder for glide.

Currently I have set the height of the imageView to a fixed 300dp.

<ImageView
        android:id="@+id/meme_image"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginTop="8dp"
        android:scaleType="fitCenter"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/meme_user_title"
        tools:srcCompat="@tools:sample/avatars" />

Here's what I have done with glide

Glide.with(context)
            .load(memes[position].url)
            .placeholder(circularProgressDrawable)
            .transition(DrawableTransitionOptions.withCrossFade())
            .into(holder.img)

I have tried setting up the imageView height as wrap content but it looks very odd as the image pops out instantly that does not look good. I want images to have a certain height at start with the glide placeholder and when the image is loaded it should resize itself to the size of the image. Also, I want a maximum height of the ImageView so that if an image a very large then it should not take the whole view on the screen.

Upvotes: 0

Views: 28

Answers (1)

REX
REX

Reputation: 149

You can try using a Staggered Grid Layout Manager as your recyclerview layout manager. Below is the link to the official doc and a tutorial.
Official doc
Sample tutorial

Upvotes: 0

Related Questions