<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                以下為個人總結回顧,不喜勿噴。 github地址[鏈接](https://github.com/nostra13/Android-Universal-Image-Loader) 作為很早就出名的一個圖片緩存框架,用起來還是很方便的。 - **在gradle構建腳本中添加** ~~~ compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' ~~~ - **在配置文件中添加相應的權限** ~~~ <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ~~~ - **在Application中初始化** 在這里我們需要初始化一個ImageLoader,并且配置我們項目中可會會用到的DisplayImageOptions。 ImageLoader的初始化,ImageLoader是一個單例對象,我們在需要使用他的時候直接getInstance()即可。但是,在此之前,我們需要初始化。 ~~~ public void getNormalImageloader(){ ImageLoaderConfiguration configuration = ImageLoaderConfiguration.createDefault(getApplicationContext()); /** * 初始化 */ ImageLoader.getInstance().init(configuration); } ~~~ 上面用的是默認的初始化參數,絕大多數情況下我們會這樣用。但是,有時候我們也需要配置一些參數。這時,我們就需要 ~~~ public void getMyImageloader(){ File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext()); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) // .taskExecutor(...) // .taskExecutorForCachedImages(...) // .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 1) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default .defaultDisplayImageOptions(normal_options) .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(getApplicationContext())) // default .imageDecoder(new BaseImageDecoder(true)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); } ~~~ 上面不做多介紹。很簡單看字面意思就知道了。我們看看,他支持那些參數設置呢。 com.nostra13.universalimageloader.core.ImageLoaderConfiguration.Builder類中 ![](https://box.kancloud.cn/2016-04-08_570768056c694.jpg "") 小伙伴們根據需求配置就好。 接下來我們看DisplayOption參數的配置 ~~~ default_options = new DisplayImageOptions.Builder() /** * 這只Uri為空、加載失敗、加載時候的圖片資源,可以接受Drawable 和 資源ID */ .showImageForEmptyUri(R.mipmap.ic_launcher) .showImageOnFail(R.mipmap.ic_launcher) .showImageOnLoading(R.mipmap.ic_launcher) //是否設置在加載之前重置view .resetViewBeforeLoading(false) .delayBeforeLoading(1000) //是否緩存在內存中 .cacheInMemory(false) //是否緩存在文件中 .cacheOnDisk(false) // .preProcessor(...) // .postProcessor(...) // .extraForDownloader(...) .considerExifParams(false) //Image的縮放類型 .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) //bitmap 的config .bitmapConfig(Bitmap.Config.ARGB_8888) //decode參數 // .decodingOptions() //設置顯示,可以設置為圓角 .displayer(new SimpleBitmapDisplayer()) .handler(new Handler()) .build(); ~~~ 同樣,我們看下可以配置哪些參數。 ![](https://box.kancloud.cn/2016-04-08_570768058ca48.jpg "") 同樣 根據自己的需求設置就好,比如說我這里想設置圓角怎么辦 ~~~ head_options = new DisplayImageOptions.Builder() .showStubImage(R.mipmap.ic_launcher) .showImageOnFail(R.mipmap.ic_launcher) .showImageForEmptyUri(R.mipmap.ic_launcher) //設置圓角顯示 .displayer(new RoundedBitmapDisplayer(50)) .cacheOnDisk(true) .cacheInMemory(true) .build(); ~~~ 只需要這樣就好,那么我們在來看看displayer()可以設置什么吧。 ![](https://box.kancloud.cn/2016-04-08_57076805a4110.jpg "") > FadeinBitmapDisplayer 會在顯示的時候有個動畫效果 RoundBitmapDisplayer 可以設置圓角大小 RoundedVignetteBitmapDisplayer 出了設置圓角外,還可以設置裝飾圓角。其實就是加個margin而已 SimpleBitmapDisplay 不帶圓角 - **在代碼中設置并顯示** 使用imageloader的方法顯示,他提供了以下方法。 ![](https://box.kancloud.cn/2016-04-08_57076805b89bd.jpg "") 這里我們簡單看下就好。 一般情況下我們這樣就好 ~~~ imageLoader.displayImage("http://pic.33.la/20141114bztp/1764.jpg", normal_image,MyApplication.normal_options); ~~~ 如果在options沒有設置失敗等情況下顯示的圖片,我們還可以這樣 ~~~ imageLoader.displayImage("http://www.juzi2.com/uploads/allimg/130524/1_130524115230_1.jpg", head_image, MyApplication.head_options, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { } @Override public void onLoadingCancelled(String imageUri, View view) { } }, new ImageLoadingProgressListener() { @Override public void onProgressUpdate(String imageUri, View view, int current, int total) { Log.e("tag","還是可以進來的"); Log.e("tag","imageUri--->"+imageUri+"|||urrent--->"+current+"|||total---->"+total); tv_progress.setText(current+"/"+total); } }); ~~~ 這里的2個監聽器,一個是監聽下載狀況,另一個是監聽下載進度。 關于loadimage()和loadimagesync(),就不說了,也很簡單。 這里在多說一個叫做PauseOnScrollListener的類,這個類是讓我們判斷在listview等,滑動時候取消加載的。 好了,關于Universal-image-loader的用法就介紹這么多了。不喜勿噴
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看