photoview源码地址:
https://github.com/chrisbanes/PhotoView
PhotoView旨在简单的实现对图片的放大及缩小功能
使用方法如下:
1、先在根build.gradle加入如下代码
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
2、然后在项目文件下加入
dependencies {
implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}
3、用法比较简单
<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);
注意事项:
photoview 在放置于一些Viewgroups中,尤其是viewpager 或drawerlayout 时会出现
一些异常情况,为了防止这种情况的发生,可以仿照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; } } }