Android UI Libs之PhotoView
1. 說明
PhotoView可以幫助我們快速簡單的實現(xiàn)一個放大ImageView
中圖片的功能,這個功能在查看圖片時非常常用,通過觸摸放大圖片。
2. 配置
- 首先在工程的build.gradle上面添加JitPack倉庫
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
- 其次,在模塊的build.gradle上面添加依賴
dependencies {
compile 'com.github.chrisbanes:PhotoView:1.2.6'
}
3. 基本使用
使用該庫來放大ImageView
中圖片有兩種方式:
- 直接使用
PhoteView
在xml中定義PhoteView
:
<uk.co.senab.photoview.PhotoView
android:id="@+id/image"
android:src="@drawable/image"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent" />
程序運行界面如下:
- 配合
PhotoViewAttacher
使用ImageView
:
在xml中定義ImageView
:
<ImageView
android:id="@+id/image"
android:src="@drawable/image"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent" />
在java文件中進行相關(guān)操作:
this.image = (ImageView) findViewById(R.id.image);
mAttacher = new PhotoViewAttacher(image);
程序運行界面如下:
程序源代碼下載,我的github倉庫:UILibs