CollageImageView

This app is an example. how to create collages with RecyclerView. See an example, how it's working:

https://user-images.githubusercontent.com/12826416/115937820-81d76900-a4a1-11eb-8650-ef02fad27c12.mp4

Installation

1) If you have not added Jitpack to your repositories, add it:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

2) Then add to your app (or another module, where you will use the lib) this dependency:

implementation 'com.github.GrishinSergey:CollageImageView:v2.0.0'

3) In your layout you should place this:

<com.sagrishin.collageview.CollageView
    android:id="@+id/collageViewId"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

And in your source you should place next code.

One of major changes between v1 and v2 is that now it is necessary to provide previewer. This is the way, how this lib supports different libraries for previewing images. Look to app module to see details

collageViewId.itemPreviewLoader = GlideItemPreviewLoaderImpl.Builder(context).build()

Now it is possible to set radius for images in collage. Just paste value in dp in collage to make it rounded

val radius = TypedValue.applyDimension(
    TypedValue.COMPLEX_UNIT_DIP,
    4F, // the radius value
    context.resources.displayMetrics
).toInt()

Here is an example, how to fill list of urls to images. Let's say you have list of images from your API, so you can convert them to CollageItemUrlData

val images = photos.map { singlePhoto ->
    CollageItemUrlData(singlePhoto.url).apply {
        this.width = singlePhoto.width
        this.height = singlePhoto.height
    }
}

Last, which is necessary, call setup method. It takes now three params:

  • list of CollageItemUrlData,
  • radius
  • listener of clicks
collageViewId.setup(images, radius) { position ->
    Toast.makeText(context, "clicked position is $position", Toast.LENGTH_SHORT).show()
}

GitHub

https://github.com/GrishinSergey/CollageImageView