Universal-image-loader resolution (2) -- Detailed configuration of displayimageoptions

Source: Internet
Author: User

When using this framework, we must configure a displayimageoptions object as a parameter in imageloader. getinstance (). displayimage (). Therefore, it is necessary to explain the preparation method of this object. After the explanation, we will understand this framework in detail.

1. Default Configuration

DisplayImageOptions options = new DisplayImageOptions.Builder()    .showImageOnLoading(R.drawable.ic_stub) // resource or drawable    .showImageForEmptyUri(R.drawable.ic_empty) // resource or drawable    .showImageOnFail(R.drawable.ic_error) // resource or drawable    .resetViewBeforeLoading(false)  // default    .delayBeforeLoading(1000)    .cacheInMemory(false) // default    .cacheOnDisk(false) // default    .preProcessor(...)    .postProcessor(...)    .extraForDownloader(...)    .considerExifParams(false) // default    .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default    .bitmapConfig(Bitmap.Config.ARGB_8888) // default    .decodingOptions(...)    .displayer(new SimpleBitmapDisplayer()) // default    .handler(new Handler()) // default    .build();

 

Example:

/*** Display all configurations of the image * @ return */private displayimageoptions getwholeoptions () {displayimageoptions Options = new displayimageoptions. builder (). showimageonloading (R. drawable. loading) // sets the image displayed during the download process. showimageforemptyuri (R. drawable. ic_launcher) // sets the image to be displayed when the image URI is null or incorrect. showimageonfail (R. drawable. error) // set the image displayed when an error occurs during image loading/decoding. cacheinmemory (true) // sets whether the downloaded image is cached in memory. cacheondisk (true) // sets whether the downloaded image is cached on the SD card.. Considerexifparams (true) // determines whether to consider the JPEG image EXIF parameter (rotation, flip ). imagescaletype (imagescaletype. in_sample_int) // sets how the image is encoded. bitmapconfig (bitmap. config. rgb_565) // sets the image decoding type //. decodingoptions (bitmapfactory. options decodingoptions) // sets the image decoding configuration. delaybeforeloading (0) // int delayinmillis sets the delay time before downloading for you // sets the bitmap before adding the image to the cache //. preprocessor (bitmapprocessor Preprocessor ). resetviewbeforeloading (true) // sets whether the image is reset before download, Reset. displayer (New roundedbitmapdisplayer (20) // not recommended !!!! Whether to set to rounded corner and radians. displayer (New fadeinbitmapdisplayer (100) // specifies whether the animation is updated after the image is loaded. The animation may flash. build (); // return options after the build is complete ;}

 

2. Common configurations

/*** Set common settings ** @ return */private displayimageoptions getsimpleoptions () {displayimageoptions = new displayimageoptions. builder (). showimageonloading (R. drawable. loading) // sets the image displayed during the download process. showimageforemptyuri (R. drawable. ic_launcher) // sets the image to be displayed when the image URI is null or incorrect. showimageonfail (R. drawable. error) // set the image displayed when an error occurs during image loading/decoding. cacheinmemory (true) // sets whether the downloaded image is cached in memory. cacheondisk (true) // sets whether the downloaded image is cached in the SD card. imagescaletype (imagescaletype. in_sample_int) // sets how the image is encoded. bitmapconfig (bitmap. config. rgb_565) // sets the image decoding type. build (); // return options after the build is complete ;}

 

Note: The parameters here can also be modified at will, depending on the project needs!

 

Notes:

1). imagescaletype (imagescaletype) // set the image scaling mode, for example:

.imageScaleType(ImageScaleType.IN_SAMPLE_INT)

Here, select the value of magescaletype:
Exactly: the size of the target image that will be scaled down in proportion.
Exactly_stretched: The image is scaled to the target size.
In_sample_int: integer multiple of the image to be sampled twice
In_sample_power_of_2: The image will be reduced by 2 times until the next step is reduced to make the image smaller.
None: The image is not adjusted.

2). displayer (bitmapdisplayer displayer) // sets the image display mode, for example:

.displayer(new FadeInBitmapDisplayer(100))

Here, the displayer selection value:

Roundedbitmapdisplayer (INT roundpixels) sets the rounded corner image. It is not recommended !!!
The fakebitmapdisplayer () class does nothing.
Fadeinbitmapdisplayer (INT durationmillis) sets the time when the image is gradually displayed.
Simplebitmapdisplayer () normally displays an image

 

3. Avoid OOM

. Bitmapconfig (bitmap. config. rgb_565) // The default value is argb_8888. rgb_565 is twice less than argb_8888.

Use. imagescaletype (imagescaletype. in_sample_int) or imagescaletype (imagescaletype. Exactly)

Avoid using. displayer (New roundedbitmapdisplayer (20) // It will create a new bitmap object in the argb_8888 format;

 

Activity Code:

 

Reference:

Http://blog.csdn.net/xiaanming/article/details/26810303

Http://blog.csdn.net/vipzjyno1/article/details/23206387

 

Universal-image-loader resolution (2) -- Detailed configuration of displayimageoptions

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.