Fresco使用教程(一)
來自: http://xunhou.me/fresco-1/
摘要
Fresco是非死book最新推出的一款用于Android應用中展示圖片的強大圖片庫,可以從網絡、本地存儲和本地資源中加載圖片。其中的Drawees可以顯示占位符,直到圖片加載完成。而當圖片從屏幕上消失時,會自動釋放內存。
快速開始
你可以通過Maven Central下載Fresco
-
通過Gradle
dependencies {
compile 'com.非死book.fresco:fresco:0.1.0+'
}
-
通過Maven
com.非死book.fresco fresco LATEST
Fresco入門
如果你想下載顯示一張圖片,并且在加載過程中用占位圖來顯示它,就可以用SimpleDraweeView。
首先你想展示網絡上的圖片,需要在你的清單文件中聲明聯網權限
<uses-permission android:name="android.permission.INTERNET"/>
在app啟動過程中,在你調用setContextView()之前要初始化Fresco這個類
Fresco.initialize(context);
在Xml中,新增一個自定義的命名空間在最外層
<!-- Any valid element will do here --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent" android:layout_width="match_parent">
然后在布局中添加SimpleDraweeView控件
<com.非死book.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" />
你只需要在代碼中這樣寫就可以成功顯示圖片了。
Uri uri = Uri.parse("http://frescolib.org/static/fresco-logo.png"); SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view); draweeView.setImageURI(uri);
URI的支持
Type | Scheme | Fetch method used |
---|---|---|
File on network | http://, https:// | HttpURLConnection or network layer |
File on device | file:// | FileInputStream |
Content provider | content:// | ContentResolver |
Asset in app | asset:/ | AssetManager |
Resource in app | res:// | Resources.openRawResource |
相信大家看完上面的QUICK START,已經可以簡單的使用Fresco了,下篇來看一下Drawees的各種特性。
</div> 本文由用戶 1450879387 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!