Android optimization is the most common is the ListView, Gallery, GridView, Viewpager Big Data optimization picture optimized access network optimization
Optimization principle: Data delay loading local cache in batches
Data optimization 1). Multiplexing Contentview
2). Create a static class Viewholder
3). batch load Slide monitor or button to show more data drag down to display
Picture optimization 1). Asynchronous loading
2). Local cache (level two cache memory (soft reference implementation), SD card)
3). Do not show pictures when sliding quickly
4). Divided into core thread pool and common thread pool, download pictures and other time-consuming tasks placed in the normal thread pool
Asynchronous loading Asyntask Android packaged asynchronous data acquisition, including three methods
Doinbackground executing async methods in a child thread
Onprogressupdate the method that is executed after data acquisition, where the UI interface can be updated in the main thread
OnPostExecute methods that are executed in the main thread before the asynchronous method can be performed with friendly hints
You can also encapsulate a task class (a child thread) thread pool it needs to maintain a task list and prioritize tasks.
Code optimized for adapter:
Java code
- Public class Holderadapter<e> extends abstractadapter<e> {
- Public Holderadapter (Layoutinflater inflater, viewcreator<e> creator) {
- Super (Inflater, creator);
- }
- private static class viewholder{
- Public view view;
- }
- @Override
- Public View GetView (int position, View Convertview, ViewGroup parent) {
- //Holder view mode implementation
- if (Convertview = = null) {
- Viewholder holder = new Viewholder ();
- Convertview = Mcreator.createview (Minflater, Position,getitem (position));
- Holder.view = Convertview;
- Convertview.settag (holder);
- } Else {
- Viewholder holder = (viewholder) convertview.gettag ();
- //Release the current view data
- Mcreator.releaseview (Convertview, GetItem (position));
- //Update new data to Hodlerview
- Mcreator.updateview (Holder.view, Position, GetItem (position));
- }
- return convertview;
- }
- }
Android, Baseadapter optimization when dealing with large data volumes