Android-Universal-Image-Loader loads images,
Directly look at the code: MainActivity:
Package com. example. textwsjdemo; import com. nostra13.universalimageloader. cache. disc. naming. md5FileNameGenerator; import com. nostra13.universalimageloader. core. displayImageOptions; import com. nostra13.universalimageloader. core. imageLoader; import com. nostra13.universalimageloader. core. imageLoaderConfiguration; import com. nostra13.universalimageloader. core. assist. queueProcessingType; import com. nostra13.universalimageloader. core. display. roundedBitmapDisplayer; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. imageView; public class MainActivity extends Activity {private String url; private Button bt_hehe; private ImageView iv_photo; private DisplayImageOptions defaultOptions; private ImageLoaderConfiguration config; @ Override protected void onCreate (Bundle detail) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView (); defaultOptions = new DisplayImageOptions. builder (). showStubImage (R. drawable. ic_launcher) // loads the default image starting from. showImageForEmptyUri (R. drawable. ic_launcher) // If the url is null, the image is displayed and placed in drawable. showImageOnFail (R. drawable. ic_launcher) // This image is displayed when an error occurs when loading the image. cacheInMemory (true) // cache is not cached with fslae. cacheOnDisc (true) // used for caching. displayer (new RoundedBitmapDisplayer (5) // display the rounded corner of the image. The value is an integer. build (); config = new ImageLoaderConfiguration. builder (MainActivity. this ). defaultDisplayImageOptions (defaultOptions ). threadPriority (Thread. NORM_PRIORITY-2 ). denyCacheImageMultipleSizesInMemory (). discCacheFileNameGenerator (new Md5FileNameGenerator ()). tasksProcessingOrder (QueueProcessingType. LIFO )//. enableLogging () // Not necessary in common. build (); ImageLoader. getInstance (). init (config);} private void initView () {// picture URLurl = "http://file.koolearn.com/20131018/1382077932449.jpg"; bt_hehe = (Button) findViewById (R. id. bt_hehe); iv_photo = (ImageView) findViewById (R. id. iv_photo); bt_hehe.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubImageLoader. getInstance (). displayImage (url, iv_photo, defaultOptions); // The url is the image address, and the iv_photo is the ImageView layout ,}});}}
This code can load network images and import the jar package of Image-Loader.
Image-Loader download: https://github.com/nostra13/Android-Universal-Image-Loader
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.