PhotoView 图片展示
PhotoView 旨在帮助生成一个易于使用的缩放 Android ImageView 实现。

依赖
将此添加到您的根build.gradle文件(不是您的模块build.gradle文件)中:
allprojects {
    repositories {
        maven { url "https://www.jitpack.io" }
    }
}
buildscript {
    repositories {
        maven { url "https://www.jitpack.io" }
    }	
}
然后,将库添加到您的模块中 build.gradle
dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}
特征
- 开箱即用的缩放,使用多点触控和双击。
- 滚动,平滑滚动。
- 在滚动父级(例如 ViewPager)中使用时效果很好。
- 允许在显示的矩阵更改时通知应用程序。当您需要根据当前缩放/滚动位置更新 UI 时很有用。
- 允许在用户点击照片时通知应用程序。
用法
提供的示例展示了如何以更高级的方式使用库,但为了完整起见,以下是让 PhotoView 工作所需的全部内容:
<com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setImageResource(R.drawable.image);
就是这样!
视图组的问题
有一些 ViewGroups(使用 onInterceptTouchEvent 的那些)在放置 PhotoView 时抛出异常,最显着的是ViewPager和DrawerLayout。这是一个尚未解决的框架问题。为了防止此异常(通常在缩小时发生),请查看HackyDrawerLayout,您可以看到解决方案是简单地捕获异常。任何使用 onInterceptTouchEvent 的 ViewGroup 也需要扩展并捕获异常。使用HackyDrawerLayout作为如何执行此操作的模板。基本实现是:
public class HackyProblematicViewGroup extends ProblematicViewGroup {
    public HackyProblematicViewGroup(Context context) {
        super(context);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
						//uncomment if you really want to see these errors
            //e.printStackTrace();
            return false;
        }
    }
}
与 Fresco 一起使用
由于 Fresco 的复杂性,该库目前不支持 Fresco。见这个项目作为一种替代解决方案。
github地址:https://github.com/Baseflow/PhotoView
下载地址:master.zip
 
			