Android-Universal-Image-Loader loads images,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.