UI controls such as Recyclerview,listview,gridview and their optimizations and picture misalignment--

Source: Internet
Author: User

--------------------------------Picture Dislocation problem---------------------------------------

Law One:

1: The picture is preset to a local placeholder picture first. Important A lot of dislocation is the reuse of other locations of the image cache, and the current picture is not loaded, resulting in the current picture dislocation. So the solution is to use a local placeholder image to quickly refresh the current picture. After loading, you can replace the placeholder image. );

2: Through ImageView. settag, the URL is recorded inside the picture;

3: Put the URL into a request queue (this is to avoid a large picture, the request takes a long time, repeatedly initiating a URL request);

4: If the request queue has a URL, the old URL corresponds to the picture control, replaced by this request picture control, return;

5. If the current URL and the first step ImageView. Gettag is consistent, update the picture with the new data source, otherwise return;

6. If the image is reused, it is best to write to the local storage after access, avoiding time consuming network requests.

Law II:

Use weak reference associations (not very clear!!!)

Fahsarm

Using the Networkimageview provided by the volley framework:

private void Netrequestimage () {

Imageloader loader = new Imageloader (Myapplication.requestqueue, New Imageloader.imagecache () {
@Override
Public Bitmap getbitmap (String URL) {
return null;
}

@Override
public void Putbitmap (String url, Bitmap Bitmap) {

}
});
Iv3.setdefaultimageresid (R.mipmap.ic_launcher);
Iv3.seterrorimageresid (R.mipmap.ic_launcher);
Iv3.setimageurl ("http://pic14.nipic.com/20110522/7411759_164157418126_2.jpg", loader);
}

-------------------the use of three kinds of controls----------------------

1. Prepare the data source

2. New Adapter

3. Load Adapter

--------------------------Optimization Problems-----------------------

1, if the custom adapter, then in the GetView method to consider the method passed in the parameter contentview is null, if it is null to create Contentview and return, if not NULL is directly used. Create as few view as possible in this method.

2, to Contentview set tag (Settag ()), passed in a Viewholder object, used to cache the data to be displayed, can achieve the effect of asynchronous loading of image data.

3. If the ListView needs to display a lot of item, you should consider paging load. For example, to show a total of 100 or more times, we can consider loading 20 first, and so on when the user pulls to the bottom of the list to load the next 20.

4, control the number of threads + data paging load;

5, rewrite the onscrollstatechanged method;

UI controls such as Recyclerview,listview,gridview and their optimizations and picture misalignment--

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.