ImageLoader加載圖片

先導universal-image-loader-1.9.3包

在application配置?android:name=".MyApplication"

intent權限

復制代碼
 1 package com.ch.day13_imageloaderdemo;
 2 
 3 import java.io.File;
 4  5 import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;  6 import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;  7 import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;  8 import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;  9 import com.nostra13.universalimageloader.core.DisplayImageOptions; 10 import com.nostra13.universalimageloader.core.ImageLoader; 11 import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 12 import com.nostra13.universalimageloader.core.assist.ImageScaleType; 13 import com.nostra13.universalimageloader.core.assist.QueueProcessingType; 14 import com.nostra13.universalimageloader.core.decode.BaseImageDecoder; 15 import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; 16 import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer; 17 import com.nostra13.universalimageloader.core.download.BaseImageDownloader; 18 19 import android.app.Application; 20 import android.graphics.Bitmap; 21 import android.os.Environment; 22 import android.util.Log; 23 24 public class MyApplication extends Application{ 25 26  @Override 27 public void onCreate() { 28 // TODO Auto-generated method stub 29  super.onCreate(); 30 Log.i("TAG", "自定義的application類調用了....."); 31 //創建ImageLoader的默認配置 32 // ImageLoaderConfiguration confing = ImageLoaderConfiguration.createDefault(this); 33 //得到sdcard路徑 34 String sdpath = Environment.getExternalStorageDirectory().getPath(); 35 //自定義ImageLoaderConfiguration 36 ImageLoaderConfiguration confing = new ImageLoaderConfiguration.Builder(this) 37 .memoryCacheExtraOptions(480, 800)// default = device screen dimensions 內存緩存文件的最大長寬 38 .diskCacheExtraOptions(480, 800, null)// 本地緩存的詳細信息(緩存的最大長寬),最好不要設置這個 39 // .taskExecutor(null) 40 // .taskExecutorForCachedImages(null) 41 .threadPoolSize(3)// default 線程池內加載的數量 42 .threadPriority(Thread.NORM_PRIORITY-2) // default 設置當前線程的優先級 43 .tasksProcessingOrder(QueueProcessingType.FIFO)//任務的處理順序 44  .denyCacheImageMultipleSizesInMemory() 45 .memoryCache(new LruMemoryCache(2 * 1024 * 1024))////設置自己的內存緩存大小 2m 46 .memoryCacheSize(2 * 1024 * 1024) 47 // .memoryCacheSizePercentage(13) 48 .diskCache(new UnlimitedDiscCache(new File(sdpath+"/app1407a/imgcache")))//設置緩存的圖片在sdcard中的存放位置 49 .diskCacheSize(50 * 1024 * 1024) 50 .diskCacheFileCount(100) 51 .diskCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator() 52 .imageDownloader(new BaseImageDownloader(this)) 53 // .imageDecoder(new BaseImageDecoder(true)) 54  .defaultDisplayImageOptions(null)//不適用默認的圖片加載配置,使用自定義的 55  .writeDebugLogs() 56  .build(); 57 //初始化 58  ImageLoader.getInstance().init(confing); 59  } 60 61 public static DisplayImageOptions getOptions(){ 62 //自定義加載圖片的配置信息 63  DisplayImageOptions option = new DisplayImageOptions.Builder() 64 .showImageOnLoading(R.drawable.ic_launcher)// 設置圖片下載期間顯示的圖片 65 .showImageForEmptyUri(R.drawable.emptyurl) // 設置圖片Uri為空或是錯誤的時候顯示的圖片 66 .showImageOnFail(R.drawable.emptyurl)// 設置圖片加載或解碼過程中發生錯誤顯示的圖片 67 .resetViewBeforeLoading(false)// default 設置圖片在加載前是否重置、復位 68 // .delayBeforeLoading(1000)// 下載前的延遲時間 69 .cacheInMemory(true)// default 設置下載的圖片是否緩存在內存中 70 .cacheOnDisk(true)// default 設置下載的圖片是否緩存在SD卡中 71 .considerExifParams(false) 72 .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//設置圖片的顯示比例 73 .bitmapConfig(Bitmap.Config.RGB_565)// default 設置圖片的解碼類型 74 // .displayer(new RoundedBitmapDisplayer(75))//設置圖片的圓角半徑 75 .displayer(new FadeInBitmapDisplayer(8000))//設置圖片顯示的透明度過程時間 76 .build(); 77 78 return option; 79 } 80 81 }
復制代碼
復制代碼
 1 package com.ch.day13_imageloaderdemo;
 2 
 3 import com.nostra13.universalimageloader.core.ImageLoader;
 4 import com.nostra13.universalimageloader.core.assist.FailReason;  5 import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;  6 import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;  7  8 import android.os.Bundle;  9 import android.app.Activity; 10 import android.app.ProgressDialog; 11 import android.graphics.Bitmap; 12 import android.util.Log; 13 import android.view.Menu; 14 import android.view.View; 15 import android.widget.ImageView; 16 17 public class MainActivity extends Activity { 18 private ImageView img; 19 String url = "http://photocdn.sohu.com/kis/fengmian/1193/1193693/1193693_ver_big.jpg"; 20 String url1 = "http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg"; 21  @Override 22 protected void onCreate(Bundle savedInstanceState) { 23  super.onCreate(savedInstanceState); 24  setContentView(R.layout.activity_main); 25 26  init(); 27  } 28 29 public void init(){ 30 img = (ImageView) findViewById(R.id.img); 31 //通過ImageLoader加載網絡圖片,配置給img 32 // ImageLoader.getInstance().displayImage(url, img); 33 // ImageLoader.getInstance().displayImage(url, img, MyApplication.getOptions()); 34 // ImageLoader.getInstance().displayImage(url, img, MyApplication.getOptions(), new ImageLoadingListener() { 35 // @Override 36 // public void onLoadingStarted(String arg0, View arg1) { 37 // } 38 // @Override 39 // public void onLoadingFailed(String arg0, View arg1, FailReason arg2) { 40 // } 41 // @Override 42 // public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) { 43 // } 44 // @Override 45 // public void onLoadingCancelled(String arg0, View arg1) { 46 // } 47 // }); 48 final ProgressDialog pro = new ProgressDialog(this); 49 pro.setMessage("努力加載中。。。"); 50  pro.setIcon(R.drawable.ic_launcher); 51  pro.show(); 52 ImageLoader.getInstance().displayImage(url1, img, MyApplication.getOptions(), null, new ImageLoadingProgressListener() { 53 54  @Override 55 public void onProgressUpdate(String arg0, View arg1, int arg2, int arg3) { 56 // TODO Auto-generated method stub 57 Log.i("TAG", arg0+",,"+arg2+","+arg3); 58 float rs = ((float)arg2)/arg3; 59 pro.setMessage("當前加載到:"+rs*100+"%"); 60 if(arg2 == arg3){ 61  pro.cancel(); 62  } 63  } 64  }); 65  } 66 67  @Override 68 public boolean onCreateOptionsMenu(Menu menu) { 69 // Inflate the menu; this adds items to the action bar if it is present. 70  getMenuInflater().inflate(R.menu.activity_main, menu); 71 return true; 72 } 73 74 }
復制代碼

轉載于:https://www.cnblogs.com/wbp0818/p/5458519.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/396096.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396096.shtml
英文地址,請注明出處:http://en.pswp.cn/news/396096.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

hackintosh黑蘋果_為什么您的下一個Mac應該是Hackintosh?

hackintosh黑蘋果by Sebastian Dobrincu塞巴斯蒂安多布林庫(Sebastian Dobrincu) 為什么您的下一個Mac應該是Hackintosh? (Why Your Next Mac Should Be a Hackintosh ?) I just finished a 48-hour Hackintosh building marathon. It was a fun experience and I…

一張圖解釋什么是遺傳算法_遺傳算法簡介及代碼詳解

(allele)數據值,屬性,值基因座(locus)位置,iterator位置表現型(phenotype)參數集,解碼結構,候選解染色體:又可以叫做基因型個體(individuals)群體/種群(population):一定數量的個體組成&#xf…

c語言程序設計學生程序查詢,《c語言程序設計報告-學生信息管理系統》.doc

《c語言程序設計報告-學生信息管理系統》中南大學??C語言程序設計實踐報告?????題 目 學生信息管理系統學生姓名 張眼指導教師 劉偉榮學 院 信息科學與工程學院專業班級 電氣信息1113班完成時間 2012年6月28日星期四?1.設計任務及設計目標學生信息管理系統是基于系統主…

ListString 和 ArrayListString的區別

最近對這兩個問題比較懵逼&#xff0c;關于List和ArrayList、List<String> list new ArrayList<String>(); 好了&#xff0c;先搞明白List 和 ArrayList吧。 List是一個接口&#xff0c;是Collection接口的一個子接口&#xff0c;是一個有序的集合。 ArrayList是L…

java城市級聯一次查詢_我的城市沒有任何設計活動,所以我自己組織了一次。...

java城市級聯一次查詢by Marty Laurita由Marty Laurita 我的城市沒有任何設計活動&#xff0c;所以我自己組織了一次。 (There weren’t any design events in my city, so I organized one myself.) “The meeting of two personalities is like the contact of two chemical…

Access denied for user 'root'@'localhost' (using password: YES) 問題解決小記

初學php&#xff0c;按照視頻安裝后好mysql后 終端運行命令 mysql -u root -p 然后輸入安裝mysql時輸入的密碼六個1&#xff0c;會報這樣的錯誤&#xff1a;Access denied for user rootlocalhost (using password: YES) &#xff1b; 百度了一大堆&#xff0c;大海撈針一般找…

匯編總結2

一、寄存器 一個典型的cpu是由運算器&#xff0c;控制器&#xff0c;寄存器等器件組成的。 內部總線實現CPU內部各個器件之間的聯系 外部總線實現cpu和主板上其他器件的聯系 AX,BX,CX,DX通用寄存器 SI,DI,BP,SP基址和變址寄存器 CS,SS,DS,ES段寄存器 IP,FLAGS指令指針和標志寄存…

創業者具備的五大技能_一、如今大學生創業需要具備哪些知識與技能?

我參加過兩次互聯網&#xff0b;大賽&#xff0c;分別獲得過省賽的金獎與銀獎&#xff0c;還曾參加山東省大大小小比賽26場&#xff0c;金獎累計獲得12次。對當代創業的大學生所應具備哪些基本素質深有體會。&#xff08;1&#xff09;技能&#xff1a;1、自我認知及科學規劃能…

c語言定時器回調函數的參數,定時器的簡單實現即回調函數的運用

&#xfeff;&#xfeff;這兩天在 研究回調函數就想實現簡單的定時器&#xff0c;如下是鄙人的程序望指教。ios#include #include using namespace std;app#define MAXNUM 256函數typedef void (*timerProcessFunc)(void*);spatypedef struct{unsigned int id;int timeout; /…

BZOJ3387柵欄行動

首先&#xff0c;很容易想到Dp。設f[i][0]表示第i個柵欄走左邊的最短路&#xff0c;f[i][1]表示第i個柵欄走右邊的最短路。 所以&#xff0c;我們要找一個剛好在第i個柵欄的左右邊界下面的柵欄。如圖所示&#xff1a; 則有&#xff1a; f[i][0] min(f[k][0] |Left[i] - Left[…

udacity開源的數據_評論:Udacity數據分析師納米學位計劃

udacity開源的數據by David Venturi大衛文圖里(David Venturi) 評論&#xff1a;Udacity數據分析師納米學位計劃 (Review: Udacity Data Analyst Nanodegree Program) Udacity’s Data Analyst Nanodegree program was one of the first online data science programs in the …

凌晨四點鐘深圳的風景

科比有過一句很勵志的故事&#xff1a;凌晨四點鐘洛杉磯的風景。 很多人把科比當成榜樣&#xff0c;不僅僅因為他精湛的球技&#xff0c;更是因為他遠超常人的職業精神。 其實做到這一點&#xff0c;并不難&#xff0c;難的是堅持。堅持那么早時間起床&#xff0c;堅持十年如一…

小程序沉浸式_古北水鎮紅葉祭嵌入戲精學院 全新文旅沉浸模式讓游客嗨起來...

2020年10月17日-24日&#xff0c;古北水鎮第二屆紅葉祭火熱來襲。今年除了“超級漫展二次元度假”的模式&#xff0c;古北水鎮與頂級沉浸互動體驗運營方——INX戲精學院合作&#xff0c;在深度體驗空間的同時&#xff0c;加入了互動式的實景游戲體驗&#xff0c;通過演員互動&a…

又拍云劉平陽,理性競爭下的技術品牌提升之道

云服務市場趨漸平穩&#xff0c;在這種情況下&#xff0c;就需要通過對某一項技術的深入應用來實現服務的精致化。同時&#xff0c;對品牌的打造和包裝也必不可少。\\又拍云在2010年開始提供云服務&#xff0c;經過多年的發展&#xff0c;以及市場策略的轉變&#xff0c;決定對…

編寫代碼的工作在哪找_編寫事件代碼如何幫助我獲得了出色的工作

編寫代碼的工作在哪找Everyone kept telling me about the importance of networking, but it was always something I blew off. I’m pretty quiet and introverted, particularly when meeting strangers. I thought I just wasn’t built for networking.每個人都在不斷告訴…

int x = 0x13 c語言,2004年7月全國高等教育自學考試微型計算機原理與接口技術試題...

課程代碼&#xff1a;02205第一部分 C語言程序設計一、單項選擇題(在每小題的四個備選答案中&#xff0c;選出一個正確答案&#xff0c;并將正確答案的序號填在題干的括號內。每小題2分&#xff0c;共10分)1.4位無符號二進制數表示的數的范圍是( )。A.0&#xff5e;9999 B.…

iOS開發簡單高效的數據存儲

在iOS開發過程中&#xff0c;不管是做什么應用&#xff0c;都會碰到數據保存的問題&#xff0c;你是用什么方法來持久保存數據的&#xff1f;這是在幾乎每一次關于iOS技術的交流或討論都會被提到的問題&#xff0c;而且大家對這個問題的熱情持續高漲。本文主要從概念上把“數據…

Oracle中Date和Timestamp的區別

Date和Timestamp精度不一樣&#xff1a; 01&#xff09;Timestamp精確到了秒的小數點&#xff08;如&#xff1a;2018-11-13 16:40:03.698&#xff09;&#xff1b; 02&#xff09;Date只精確到整數的秒&#xff08;如&#xff1a;2018-11-13 16:40:03&#xff09; 轉載于:http…

table偏見和HTML仇外心理

by Anthony Ng由Anthony Ng <table>偏見和HTML仇外心理 (<table> prejudice and HTML xenophobia) I was looking over some HTML with a student the other day when we stumbled onto a <table>.前幾天&#xff0c;當我偶然發現一個<table>時&#…

回滾機制_【巨杉數據庫SequoiaDB】巨杉 Tech | 并發性與鎖機制解析與實踐

01概述數據庫是一個多用戶使用的共享資源。當多個用戶并發地存取數據時&#xff0c;在數據庫中就會產生多個事務同時存取同一數據的情況。若對并發操作不加控制就可能會讀取和存儲不正確的數據&#xff0c;破壞數據庫的一致性。加鎖是實現數據庫并發控制的一個非常重要的技術。…