這一篇我們先來看看photoView整體的結(jié)構(gòu)
簡介:
github地址: https://github.com/chrisbanes/PhotoView
android項目依賴方式:allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.chrisbanes:PhotoView:latest.release.here'
}
簡單使用方式:
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>主要功能: 支持圖片的縮放,移動,旋轉(zhuǎn)
photoView源碼架構(gòu)
我們先來看下photoView源碼的都有什么:
photoView源碼結(jié)構(gòu).png
- Compat.class :兼容用的,目測是兼容API16之前的動畫的(先放一邊)
- CustomGestureDetector: 一個自定義的手勢檢測器,做了很多的手勢檢測
- 一堆監(jiān)聽: OnGestureListener, OnMatrixChangedListener,
OnOutsidePhotoTapListener, OnPhotoTapListener,
OnScaleChangedListener, OnSingleFlingListener,
OnViewTapListener (一看就明白) - PhotoView : 一看這名字就知道是核心類了,繼承了ImageView,然后一個看一大堆set,get方法。?感覺不是很核心唉
- PhotoViewAttacher: 從字面上看他是PhotoView的附加器,實現(xiàn)了觸摸,手勢檢測還有位置改變等監(jiān)聽。并且一大堆業(yè)務(wù)邏輯,so 這應(yīng)該才是最核心的咯。
- Util : 一些工具方法
粗略的看了下整體結(jié)構(gòu),代碼并不是很多,感覺主要就PhotoViewAttacher,PhotoView還有CustomGestureDetector這個三個類需要細看看。
本來以為PhotoView會是個核心類呢,結(jié)果打開代碼一看:
photoView.class的代碼結(jié)構(gòu).png
全是set,get方法,股摸著也不是具體實現(xiàn),在到具體代碼看看:
photoView.class具體實現(xiàn).png
果然里面都是些對PhotoViewAttacher里方法的調(diào)用。
so, 我們的研究范圍就又縮小了,只要研究PhotoViewAttacher.class和CustomGestureDetector.class就行了。