- 支持Coil图片加载器
- 支持Glide图片加载器
- 支持Fresco图片加载器
- 支持视频图片混合、GIF、图片预览
- 支持拖拽关闭
- 支持自定义页面索引指示器、进度条、Cover
- 支持原图加载策略
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
implementation "com.github.mikaelzero.mojito:mojito:$mojito_version"
//support long image and gif with Sketch
implementation "com.github.mikaelzero.mojito:SketchImageViewLoader:$mojito_version"
//load with coil
implementation "com.github.mikaelzero.mojito:coilimageloader:$mojito_version"
//load with glide
implementation "com.github.mikaelzero.mojito:GlideImageLoader:$mojito_version"
//load with fresco
implementation "com.github.mikaelzero.mojito:FrescoImageLoader:$mojito_version"
// in your application
Mojito.initialize(
GlideImageLoader.with(this),
SketchImageLoadFactory()
)
//or
//YourMojitoConfig:IMojitoConfig
Mojito.initialize(
GlideImageLoader.with(this),
SketchImageLoadFactory(),
YourMojitoConfig()
)
Mojito.with(context)
.urls(SourceUtil.getSingleImage())
.views(singleIv)
.start()
binding.recyclerView.mojito(R.id.srcImageView) {
urls(SourceUtil.getNormalImages())
position(position)
mojitoListener(
onClick = { view, x, y, pos ->
Toast.makeText(context, "tap click", Toast.LENGTH_SHORT).show()
}
)
progressLoader {
DefaultPercentProgress()
}
setIndicator(NumIndicator())
}
binding.longHorIv.mojito(SourceUtil.getLongHorImage())
Mojito.start(context) {
urls(SourceUtil.getNormalImages())
}
Mojito.start(context) {
urls(SourceUtil.getVideoImages(), SourceUtil.getVideoTargetImages())
setMultiTargetEnableLoader(object : MultiTargetEnableLoader {
override fun providerEnable(position: Int): Boolean {
return position != 1
}
})
setMultiContentLoader(object : MultiContentLoader {
override fun providerLoader(position: Int): ImageViewLoadFactory {
return if (position == 1) {
ArtLoadFactory()
} else {
SketchImageLoadFactory()
}
}
})
position(position)
views(recyclerView, R.id.srcImageView)
}
abstract class SimpleMojitoViewCallback : OnMojitoListener {
// image click
override fun onClick(view: View, x: Float, y: Float, position: Int) {
}
//image long press
override fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int) {
}
//end of min image to max image
override fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean) {
}
//activity finish,backToMin,single click
override fun onMojitoViewFinish() {
}
//when you drag your image
override fun onDrag(view: MojitoView, moveX: Float, moveY: Float) {
}
//the ratio of long image when you scroll
override fun onLongImageMove(ratio: Float) {
}
}
Name | desc |
---|---|
url(src,target) | 设置缩略图和原图url数据 |
position | 点击的位置 |
views | 1. recylclerView,imageViewId 2. single view 3. multi views |
autoLoadTarget | 默认为true,如果你设置了原图的url并且设置了autoLoadTarget(false) 你需要使用setFragmentCoverLoader来自定义view |
setProgressLoader | 当你设置了 autoLoadTarget false 才会生效 |
setIndicator | 可以选择 NumIndicator 或者 CircleIndexIndicator |
setActivityCoverLoader | 自定义Activity的覆盖层view |
setMultiContentLoader | 如果使用视频和图片混合模式,需要设置 ImageViewLoadFactory |