Android之PhotoView使用(原創)


文章大綱

一、什么是PhotoView
二、代碼實戰
三、項目源碼下載

一、什么是PhotoView

  一款 ImageView 展示框架,支持縮放,響應手勢,位於圖片排行榜的第五位,PhotoView 與上面不同的是圖片的展示功能,可以實現類似微信頭像的放大功能,還有就是很多 App 的圖片顯示響應手勢按壓式如何是現實的,這里 PhotoView 將都可以輕松實現。

二、代碼實戰

1. 添加依賴

    implementation 'com.bm.photoview:library:1.4.1' 

2. 添加圖片資源

實際項目中,該圖片可能是通過網絡請求獲取的。

 

3. 編寫xml代碼

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <com.bm.library.PhotoView android:id="@+id/photoview" android:src="@drawable/test" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.constraint.ConstraintLayout> 

3. 編寫Activity代碼

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PhotoView photoView = findViewById(R.id.photoview); photoView.enable();//設置是否允許縮放,默認是不允許的 } } 

4. 運行結果如下

 
 

三、項目源碼下載

鏈接:https://pan.baidu.com/s/1fmEDq93ghJpc4a70mH8p9Q
密碼:kkss


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM