国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2019-10-22 18:20:08
字體:
供稿:網(wǎng)友

PhotoView的簡介:

這是一個圖片查看庫,實現(xiàn)圖片瀏覽功能,支持pinch(捏合)手勢或者點擊放大縮小。支持在ViewPager中翻頁瀏覽圖片。

PhotoView 是一款擴(kuò)展自Android ImageView ,支持通過單點/多點觸摸來進(jìn)行圖片縮放的智能控件。功能實用和強(qiáng)大。

PhotoView的功能:

圖片瀏覽查看
雙指縮放
單點觸摸縮放
圖片縮放模式設(shè)置

基本用法:
導(dǎo)入jar包,布局XML里設(shè)置PhotoView
將ImageView傳入PhotoViewAttacher

代碼演示:

使用 PhotoView進(jìn)行網(wǎng)絡(luò)圖片和本地圖片的加載,縮放和點擊事件處理
布局文件中:

<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();  }   }  /**  * 加載網(wǎng)絡(luò)圖片  */  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中:

/**  * 加載網(wǎng)絡(luò)圖片時,需要對ImageLoader進(jìn)行全局配置  *  */  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");// 獲取到緩存的目錄地址  // 創(chuàng)建配置ImageLoader(所有的選項都是可選的,只使用那些你真的想定制),這個可以設(shè)定在APPLACATION里面,設(shè)置為全局的配置參數(shù)  ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(  context)  // 線程池內(nèi)加載的數(shù)量  .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> 

需要導(dǎo)入的jar包:

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

效果展示:

Android,PhotoView

jar包及源碼:下載

這個庫里面上面庫里面有bug,參考這個庫

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 义乌市| 桃源县| 五大连池市| 舞钢市| 将乐县| 融水| 弋阳县| 长寿区| 岳阳市| 深泽县| 上虞市| 建宁县| 鸡东县| 嘉禾县| 二手房| 台安县| 衢州市| 泗洪县| 富川| 丽水市| 安阳市| 宜宾县| 泰宁县| 揭阳市| 合肥市| 合川市| 亚东县| 上犹县| 永宁县| 昌图县| 施甸县| 伽师县| 且末县| 卢龙县| 孟村| 西乌珠穆沁旗| 莱州市| 青铜峡市| 桐柏县| 乌兰察布市| 泾川县|