PhotoView源碼解析系列一


這一篇我們先來看看photoView整體的結構

簡介:

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"/>

主要功能:
支持圖片的縮放,移動,旋轉

photoView源碼架構

我們先來看下photoView源碼的都有什么:

photoView源碼結構.png
  • Compat.class :兼容用的,目測是兼容API16之前的動畫的(先放一邊)
  • CustomGestureDetector: 一個自定義的手勢檢測器,做了很多的手勢檢測
  • 一堆監聽: OnGestureListener, OnMatrixChangedListener,
    OnOutsidePhotoTapListener, OnPhotoTapListener,
    OnScaleChangedListener, OnSingleFlingListener,
    OnViewTapListener (一看就明白)
  • PhotoView : 一看這名字就知道是核心類了,繼承了ImageView,然后一個看一大堆set,get方法。?感覺不是很核心唉
  • PhotoViewAttacher: 從字面上看他是PhotoView的附加器,實現了觸摸,手勢檢測還有位置改變等監聽。并且一大堆業務邏輯,so 這應該才是最核心的咯。
  • Util : 一些工具方法

粗略的看了下整體結構,代碼并不是很多,感覺主要就PhotoViewAttacher,PhotoView還有CustomGestureDetector這個三個類需要細看看。

本來以為PhotoView會是個核心類呢,結果打開代碼一看:

photoView.class的代碼結構.png

全是set,get方法,股摸著也不是具體實現,在到具體代碼看看:

photoView.class具體實現.png

果然里面都是些對PhotoViewAttacher里方法的調用。
so, 我們的研究范圍就又縮小了,只要研究PhotoViewAttacher.class和CustomGestureDetector.class就行了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容