A custom ImageView Implementation
Supports
- Double-tap to zoom
- Pinch zoom
- Drag to pan
- Fling to pan
- Swipe to dismiss
<com.k2.zoomimageview.ZoomImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
imageView.onDrawableLoaded {
// invoked when any image is loaded, like from a library like Glide, picasso or coil
// can be used for updating progress UI
}
imageView.currentZoom = 1.5F // sets current zoom to 1.5 x
imageView.currentZoom // returns 1.5F
imageView.resetZoom()
Allow/disallow parent viewgroup to intercept touch event while zoomed in. Panning and swiping in a parent like ViewPager can cause some issues with gesture detection
imageView.disallowPagingWhenZoomed = true
Display drawable bounds and scale/translate info on the view. Can be useful when modifying/debugging the view
imageView.debugInfoVisible = true
Enable/Disable
imageView.swipeToDismissEnabled = true
Dismiss callback. For best results use shared activity/fragment transition
imageView.onDismiss = {
finishAfterTransition() or finish()
}
Track swipe to dismiss progress. Can be used to update UI accordingly
dismissProgressListener = { progress ->
bgView.alpha = 1.0f - progress
}
- Support for multiple scale types (only fit-center works for now)
- Publish as a library (maybe)
Huge thanks to Chris Banes for his PhotoView library
Casey Horner for this photo on unsplash
Feel free to use this file in your code. Just download and add to your project