欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)中ImageLoder進(jìn)行圖片加載和緩存

 更新時(shí)間:2016年04月10日 16:10:43   作者:zenglongfei  
這篇文章主要介紹了Android開發(fā)中ImageLoder進(jìn)行圖片加載和緩存的相關(guān)資料,需要的朋友可以參考下

圖片處理類:

package com.longfei.admin.imageloder_text;
 
import android.app.Application;
import android.graphics.Bitmap;
import android.os.Environment;
 
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
 
import java.io.File;
 
/**
 * Created by admin on 2016/4/9.
 */
public class ImageLoading extends Application {
  @Override
  public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
        this)
        .memoryCacheExtraOptions(480, 800)
            // max width, max height,即保存的每個(gè)緩存文件的最大長寬
        .discCacheExtraOptions(480, 800, null)
            // Can slow ImageLoader, use it carefully (Better don't use
            // it)/設(shè)置緩存的詳細(xì)信息,最好不要設(shè)置這個(gè)
        .threadPoolSize(3)
            // 線程池內(nèi)加載的數(shù)量
        .threadPriority(Thread.NORM_PRIORITY - 2)
        .denyCacheImageMultipleSizesInMemory()
        .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
            // You can pass your own memory cache
            // implementation/你可以通過自己的內(nèi)存緩存實(shí)現(xiàn)
        .memoryCacheSize(2 * 1024 * 1024)
        .discCacheSize(50 * 1024 * 1024)
        .discCacheFileNameGenerator(new Md5FileNameGenerator())
            // 將保存的時(shí)候的URI名稱用MD5 加密
        .tasksProcessingOrder(QueueProcessingType.LIFO)
        .discCacheFileCount(100)
            // 緩存的文件數(shù)量
        .discCache(
            new UnlimitedDiscCache(new File(Environment
                .getExternalStorageDirectory()
                + "/myApp/imgCache")))
            // 自定義緩存路徑
        .defaultDisplayImageOptions(getDisplayOptions())
        .imageDownloader(
            new BaseImageDownloader(this, 5 * 1000, 30 * 1000))
        .writeDebugLogs() // Remove for release app
        .build();// 開始構(gòu)建
    ImageLoader.getInstance().init(config);
  }
 
  private DisplayImageOptions getDisplayOptions() {
    DisplayImageOptions options;
    options = new DisplayImageOptions.Builder()
        .showImageOnLoading(R.drawable.ic_launcher) // 設(shè)置圖片在下載期間顯示的圖片
        .showImageForEmptyUri(R.drawable.ic_launcher)// 設(shè)置圖片Uri為空或是錯(cuò)誤的時(shí)候顯示的圖片
        .showImageOnFail(R.drawable.ic_launcher) // 設(shè)置圖片加載/解碼過程中錯(cuò)誤時(shí)候顯示的圖片
        .cacheInMemory(true)// 設(shè)置下載的圖片是否緩存在內(nèi)存中
        .cacheOnDisc(true)// 設(shè)置下載的圖片是否緩存在SD卡中
        .considerExifParams(true) // 是否考慮JPEG圖像EXIF參數(shù)(旋轉(zhuǎn),翻轉(zhuǎn))
        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)// 設(shè)置圖片以如何的編碼方式顯示
        .bitmapConfig(Bitmap.Config.RGB_565)// 設(shè)置圖片的解碼類型//
            // .delayBeforeLoading(int delayInMillis)//int
            // delayInMillis為你設(shè)置的下載前的延遲時(shí)間
            // 設(shè)置圖片加入緩存前,對(duì)bitmap進(jìn)行設(shè)置
            // .preProcessor(BitmapProcessor preProcessor)
        .resetViewBeforeLoading(true)// 設(shè)置圖片在下載前是否重置,復(fù)位
        .displayer(new RoundedBitmapDisplayer(20))// 是否設(shè)置為圓角,弧度為多少
        .displayer(new FadeInBitmapDisplayer(100))// 是否圖片加載好后漸入的動(dòng)畫時(shí)間
        .build();// 構(gòu)建完成
    return options;
  }
 
}
 
package com.longfei.admin.imageloder_text;
 
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
 
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
 
 
 
/**
 * 1、 Universal-ImageLoader的配置
 *
 * 2、用Universal-ImageLoader加載網(wǎng)絡(luò)圖片和本地圖片
 *
 * @author Administrator
 */
 
 
public class MainActivity extends Activity {
  private ImageLoader loader;
  private ImageView iv_img;
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    loader=ImageLoader.getInstance();//實(shí)例化ImageLoder
    iv_img=(ImageView)findViewById(R.id.iv_img);
 
    String url="file:///"+"加載本地圖片";
 
    //加載網(wǎng)絡(luò)圖片,第一個(gè)參數(shù)為路徑
//    loader.displayImage("http://static.oschina.net/uploads/user/494/988131_100.jpg?t=1419303093000",iv_img);
 
    loader.displayImage("http://static.oschina.net/uploads/user/494/988131_100.jpg?t=1419303093000", iv_img, new ImageLoadingListener() {
      @Override
      public void onLoadingStarted(String s, View view) {
        Log.i("info","加載開始");
 
      }
 
      @Override
      public void onLoadingFailed(String s, View view, FailReason failReason) {
        Log.i("info","加載失敗");
 
      }
 
      @Override
      public void onLoadingComplete(String s, View view, Bitmap bitmap) {
        Log.i("info","加載完畢");
 
      }
 
      @Override
      public void onLoadingCancelled(String s, View view) {
        Log.i("info","加載取消");
 
      }
    });
  }
}

相關(guān)文章

  • Android使用自定義View實(shí)現(xiàn)橫行時(shí)間軸效果

    Android使用自定義View實(shí)現(xiàn)橫行時(shí)間軸效果

    這篇文章主要給大家介紹了關(guān)于Android使用自定義View實(shí)現(xiàn)橫行時(shí)間軸效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Android具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Android實(shí)現(xiàn)自定義飄雪效果

    Android實(shí)現(xiàn)自定義飄雪效果

    隨著冬季的腳步越來越遠(yuǎn),南方的我今年就看了一場雪,下一場雪遙遙無期,那我們來實(shí)現(xiàn)一個(gè)自定義的 View,它能模擬雪花飄落的景象,所以本文給大家介紹了基于Android實(shí)現(xiàn)自定義飄雪效果,感興趣的朋友可以參考下
    2024-01-01
  • 非常簡單的Android打開和保存對(duì)話框功能

    非常簡單的Android打開和保存對(duì)話框功能

    這篇文章主要介紹了非常簡單的Android打開和保存對(duì)話框功能,感興趣的小伙伴們可以參考一下
    2016-07-07
  • android檢測網(wǎng)絡(luò)連接狀態(tài)示例講解

    android檢測網(wǎng)絡(luò)連接狀態(tài)示例講解

    網(wǎng)絡(luò)的時(shí)候,并不是每次都能連接到網(wǎng)絡(luò),因此在程序啟動(dòng)中需要對(duì)網(wǎng)絡(luò)的狀態(tài)進(jìn)行判斷,如果沒有網(wǎng)絡(luò)則提醒用戶進(jìn)行設(shè)置
    2014-02-02
  • 詳解android與服務(wù)端交互的兩種方式

    詳解android與服務(wù)端交互的兩種方式

    這篇文章主要介紹了詳解android與服務(wù)端交互的兩種方式,此處介紹兩種方式:使用Google原生的Gson解析json數(shù)據(jù),使用JSONObject解析json數(shù)據(jù),有興趣的可以了解一下
    2017-07-07
  • android實(shí)現(xiàn)緩存圖片等數(shù)據(jù)

    android實(shí)現(xiàn)緩存圖片等數(shù)據(jù)

    本文給大家分享的是Android采用LinkedHashMap自帶的LRU 算法緩存數(shù)據(jù)的方法和示例,有需要的小伙伴可以參考下。
    2015-07-07
  • Android開發(fā)之ClipboardManager剪貼板功能示例

    Android開發(fā)之ClipboardManager剪貼板功能示例

    這篇文章主要介紹了Android開發(fā)之ClipboardManager剪貼板功能,結(jié)合簡單實(shí)例形式分析了Android使用ClipboardManager實(shí)現(xiàn)剪貼板功能的相關(guān)操作技巧,需要的朋友可以參考下
    2017-03-03
  • Android Studio 實(shí)現(xiàn)將support庫改成Androidx

    Android Studio 實(shí)現(xiàn)將support庫改成Androidx

    這篇文章主要介紹了Android Studio 實(shí)現(xiàn)將support庫改成Androidx,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Android編程之控件狀態(tài)配置文件實(shí)例

    Android編程之控件狀態(tài)配置文件實(shí)例

    這篇文章主要介紹了Android編程之控件狀態(tài)配置文件,以實(shí)例形式分析了Android控件狀態(tài)配置文件對(duì)于選中、獲得焦點(diǎn)、按下時(shí)的狀態(tài)等相關(guān)設(shè)置技巧,需要的朋友可以參考下
    2016-01-01
  • android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    這篇文章主要為大家介紹了android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11

最新評(píng)論