CollageImageView
This app is an example. how to create collages with RecyclerView. See an example, how it's working:
device-2021-04-24-015545.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:<actual-lib-version>'
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
)
collageViewId.itemCornerRadius = radius.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
}
}
collageViewId.setItemDatas(images)
Also it is possible to listen, on which image user clicked:
collageViewId.clickListener = OnCollageClickListener { position ->
Toast.makeText(context, "clicked position is $position", Toast.LENGTH_SHORT).show()
}
Last, which is necessary, call showCollage method:
collageViewId.showCollage()
What should be upgraded:
- Make thumbnail and error holders which will be shown, if image still loading or if an error acquired
- Create proguard file