ZoomableDraweeView 博客地址
基于 Fresco 的 zoomable 实现类 PhotoView 效果
- 调整缩放倍数与 PhotoView 一致
- View 重新可见时屏蔽重置缩放倍数
- 实现单击事件的监听
- 使用便捷性优化
dependencies { ...... //Fresco 图片加载库 api 'com.facebook.fresco:fresco:2.0.0' }
//初始化 Fresco.initialize(this.applicationContext)
2.复制 library/fresco/ 下的所有类到项目中
3.xml 中引用 MyZoomableImageView
<com.ziwenl.library.fresco.MyZoomableImageView
android:id="@+id/iv_picture"
android:layout_width="match_parent"
android:layout_height="match_parent" />
4.填充图片及属性设置
val isUrl = intent.getBooleanExtra(EXTRA_KEY_IS_URL, false)
if (isUrl) {
//加载网络图片
iv_picture.setImageUrl("https://www.helloimg.com/images/2020/05/18/splash_bgb5d0ea1e3c8a4cc8.jpg")
} else {
//加载本地资源图片
iv_picture.setImageRes(R.mipmap.splash_bg)
}
//保存缩放状态 -- 当前 view 重新可见时不重置缩放倍数
iv_picture.setSaveScale(true)
//点击事件
iv_picture.setOnClickListener {
Toast.makeText(this, "点击", Toast.LENGTH_SHORT).show()
}