Android第三方控件PhotoView使用方法详解

Android第三方控件PhotoView使用方法详解,第1张

概述PhotoView的简介:这是一个图片查看库,实现图片浏览功能,支持pinch(捏合)手势或者点击放大缩小。支持在ViewPager中翻页浏览图片。

PhotoVIEw的简介:

这是一个图片查看库,实现图片浏览功能,支持pinch(捏合)手势或者点击放大缩小。支持在VIEwPager中翻页浏览图片。

PhotoVIEw 是一款扩展自AndroID ImageVIEw ,支持通过单点/多点触摸来进行图片缩放的智能控件。功能实用和强大。

PhotoVIEw的功能:

图片浏览查看
双指缩放
单点触摸缩放
图片缩放模式设置

基本用法:
导入jar包,布局XML里设置PhotoVIEw
将ImageVIEw传入PhotoVIEwAttacher

代码演示:

使用 PhotoVIEw进行网络图片和本地图片的加载,缩放和点击事件处理
布局文件中:

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:tools="http://schemas.androID.com/tools"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  tools:context=".MainActivity"  androID:orIEntation="vertical"  >   <uk.co.senab.photovIEw.PhotoVIEw  androID:ID="@+ID/iv_photo1"  androID:layout_wIDth="match_parent"  androID:layout_height="wrap_content"   />  <uk.co.senab.photovIEw.PhotoVIEw  androID:ID="@+ID/iv_photo2"  androID:layout_wIDth="match_parent"  androID:layout_height="wrap_content"   />  </linearLayout> 

MainActivity中:

public class MainActivity extends Activity {  private PhotoVIEw iv_photo1;  private PhotoVIEw iv_photo2;    @OverrIDe  protected voID onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentVIEw(R.layout.activity_main);  iv_photo1 = (PhotoVIEw) findVIEwByID(R.ID.iv_photo1);  iv_photo2 = (PhotoVIEw) findVIEwByID(R.ID.iv_photo2); // localimage();  netimage();   }  /**  * 加载本地图片  *  */  private voID localimage() { // 加载本地图片,缩放处理  try { // 图片在asset目录中  inputStream is = getAssets().open("photo2.jpg");  Bitmap bm = BitmapFactory.decodeStream(is);  iv_photo1.setimageBitmap(bm);  } catch (IOException e) {  e.printstacktrace();  }   }  /**  * 加载网络图片  */  private voID netimage() {  ImageLoader loader = ImageLoader.getInstance();  loader.displayImage("https://www.baIDu.com/img/bdlogo.png",iv_photo2);  iv_photo2.setonPhotoTapListener(new OnPhotoTapListener() {   @OverrIDe  public voID onPhotoTap(VIEw arg0,float arg1,float arg2) {  Toast.makeText(MainActivity.this,"图片被点击了",10).show();  }  });   }    } 

BaseApplication中:

/**  * 加载网络图片时,需要对ImageLoader进行全局配置  *  */  public class BaseApplication extends Application {   @OverrIDe  public voID onCreate() {  super.onCreate();  initImagloader(getApplicationContext());  }   private voID initImagloader(Context context) {  file cacheDir = StorageUtils.getownCacheDirectory(context,"photovIEw/Cache");// 获取到缓存的目录地址  // 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制),这个可以设定在APPLACATION里面,设置为全局的配置参数  ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(  context)  // 线程池内加载的数量  .threadPoolSize(3).threadPriority(Thread.norM_PRIORITY - 2)  .memoryCache(new WeakMemoryCache())  .denyCacheImageMultipleSizesInMemory()  .discCachefilenameGenerator(new Md5filenameGenerator())  // 将保存的时候的URI名称用MD5 加密  .tasksProcessingOrder(QueueProcessingType.liFO)  .discCache(new UnlimiteddiscCache(cacheDir))// 自定义缓存路径  // .defaultdisplayImageOptions(displayImageOptions.createSimple())  .writeDeBUGLogs() // Remove for release app  .build();  // Initialize ImageLoader with configuration.  ImageLoader.getInstance().init(config);// 全局初始化此配置  } } 

主清单配置文件中:

<uses-permission androID:name="androID.permission.INTERNET"/>  <application  androID:name="com.zhhandroID.BaseApplication"  androID:allowBackup="true"  androID:icon="@drawable/ic_launcher"  androID:label="@string/app_name"  androID:theme="@style/Apptheme" >  <activity  androID:name=".MainActivity"  androID:label="@string/app_name" >  <intent-filter>  <action androID:name="androID.intent.action.MAIN" />   <category androID:name="androID.intent.category.LAUNCHER" />  </intent-filter>  </activity>  </application> 

需要导入的jar包:

photovIEw-library-1.2.2.jar
universal-image-loader-1.9.2_sources.jar

效果展示:

jar包及源码:下载

这个库里面上面库里面有BUG,参考这个库

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是内存溢出为你收集整理的Android第三方控件PhotoView使用方法详解全部内容,希望文章能够帮你解决Android第三方控件PhotoView使用方法详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1143367.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存