PhotoView的使用
前言
PhotoView是一个常用的图片预览控件,主要用于Android中大图查看,例如结合ViePager完成朋友圈九宫格图片预览功能,前几天我写的ViewPager分页加载数据这篇博客,可以结合起来使用,PhotoView主要的功能有,图片手势缩放,旋转,相比ImageView,用户体验更好。
今天我呢主要就介绍两个PhotoView的框架,他们各有所长!!!
第一个是(https://github.com/chrisbanes/PhotoView),这个库,应用非常广泛,start数量极高。
第二个是(https://github.com/bm-x/PhotoView),这个支持旋转功能,经常需要用到。
先看一下效果- 首先介绍第一个
- 在我们项目module build.gradle中配置
dependencies {
compile 'com.github.chrisbanes:PhotoView:2.0.0'
}
- 在xml布局中引用该控件
<uk.co.senab.photoview.PhotoView
android:id="@+id/photoview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
是不是很简单,这就结束了
- 然后介绍下第二个
- 在我们项目module build.gradle中配置
dependencies {
compile 'com.bm.photoview:library:1.4.1'
}
- 在xml布局中引用该控件
<com.bm.library.PhotoView
android:id="@+id/photoview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- java代码
PhotoView photoView = (PhotoView) findViewById(R.id.img); // 启用图片缩放功能 photoView.enable(); // 禁用图片缩放功能 (默认为禁用,会跟普通的ImageView一样,缩放功能需手动调用enable()启用) photoView.disenable(); // 获取图片信息 Info info = photoView.getInfo(); // 从普通的ImageView中获取Info Info info = PhotoView.getImageViewInfo(ImageView); // 从一张图片信息变化到现在的图片,用于图片点击后放大浏览,具体使用可以参照demo的使用 photoView.animaFrom(info); // 从现在的图片变化到所给定的图片信息,用于图片放大后点击缩小到原来的位置,具体使用可以参照demo的使用 photoView.animaTo(info,new Runnable() { @Override public void run() { //动画完成监听 } }); // 获取/设置 动画持续时间 photoView.setAnimaDuring(int during); int d = photoView.getAnimaDuring(); // 获取/设置 最大缩放倍数 photoView.setMaxScale(float maxScale); float maxScale = photoView.getMaxScale(); // 设置动画的插入器 photoView.setInterpolator(Interpolator interpolator);//设置可以缩放,默认是不支持缩放的...
photoView.disenable();