FrescoPlus - 基于Fresco圖片庫的二次封裝,只需2步就可以讓你的應用接入Fresco
FrescoPlus
基于Fresco圖片庫的二次封裝,只需2步就可以讓你的應用接入Fresco!
由于Fresco的使用和配置起來需要寫一堆代碼,沒認真看文檔和源碼根本無法很好的了解Fresco,所以基于Fresco二次封裝,配置目前基本保持最優。
使用
1、在Application初始化FrescoPlus
FrescoPlusConfig config = FrescoPlusConfig.newBuilder(this) .setDebug(true) .setTag("Sunzxyong") .setBitmapConfig(Bitmap.Config.RGB_565) .setDiskCacheDir(this.getCacheDir()) .setMaxDiskCacheSize(80) .build(); FrescoPlusInitializer.getInstance().init(this,config);
2、在xml中使用FrescoPlusView作為顯示圖片的View,然后直接使用即可,有五種加載方式,如下
<com.sunzxy.frescopluslib.widget.FrescoPlusView android:id="@+id/fresco_view" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" fresco:viewAspectRatio="1.5" />
2.1、五種加載圖片的方式:
分別提供了精簡使用和三種不同的回調,有圖片加載成功的回調和下載Bitmap成功并返回的回調。
FrescoPlusView mFrescoPlusView = (FrescoPlusView) findViewById(R.id.fresco_view); Uri uri = Uri.parse("@Override public void onFailure(Throwable throwable) { } }); //第五種.不顯示圖片直接返回Bitmap FrescoPlusFetcher.newFetcher() .withFadeDuration(350) .withRequestPriority(FrescoPriority.HIGH) .withAutoRotateEnabled(true) .build() .fetch(uri, new FPLoadCallback<Bitmap>() { @Override public void onSuccess(Uri uri, Bitmap result) { // do something } @Override public void onFailure(Uri uri, Throwable throwable) { } @Override public void onCancel(Uri uri) { } });</pre> <h3><a id="user-content-22關于fresco更多內容請看官方文檔" class="anchor" href="/misc/goto?guid=4959661564338411548" aria-hidden="true"> <svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewbox="0 0 16 16" width="16"> <path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path> </svg></a>2.2、關于Fresco更多內容,請看官方文檔</h3>
License
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!