<span id="Label3"></p><span style="background-color:inherit"><span style="background-color:inherit">optimization will be discussed in the following aspects</span></span> <ol> <ol> <li><span style="widows:auto; background-color:inherit">How to use Adapter</span></li> <li><span style="widows:auto; background-color:inherit">Backgrounds and images</span></li> <li><span style="widows:auto; background-color:inherit">Update request</span></li> <li><span style="widows:auto; background-color:inherit">views and layouts</span></li> <li><span style="widows:auto; background-color:inherit">Memory allocation</span></li> </ol> </ol><span style="color:rgb(255,0,0); background-color:inherit"><span style="color:rgb(255,0,0); background-color:inherit">adapter:</span></span>The simplest method, the slowest and least practical, updates the frequency of frames per second around 10 using Convertview recycle view, efficiency increase 200%, Update frequency per second frame Number 30 use Viewholder mode, efficiency increase 250%, Update frequency per second transmission Frame number 40 or so<span style="color:#ff0000; background-color:inherit"><span style="color:#ff0000; background-color:inherit"><span style="background-color:inherit">Backgrounds and Images:</span></span></span>Select the appropriate image size, The view background image will always fill the entire view Area: * Image size is not appropriate to cause automatic scaling * Avoid real-time scaling * preferably pre-scaled to the view size Originalim Age = Bitmap.createscaledbitmap (<span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">originalimage,//scaled Image</span></span>View.getwidth (),//view width view.getheight (),//view height true); Dual linear filter background and image update frequency, pre-scaled transmission frames per second around 50, auto-scaling about 25<span style="background-color:inherit"><span style="background-color:inherit"><span style="color:#ff0000; background-color:inherit">window Background:</span></span></span>* By default, The window has an opaque background * can sometimes not be needed.<span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"> </span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-the view at the top level is opaque</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-top-level View covers the entire window fill_parent</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">* Updating unseen backgrounds is a waste of time</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">* Delete window background</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-getWindow (). setbackgrounddrawable (null);</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-<item name= "android:windowbackground" > @null </item></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">window background Update frequency, the background of the number of frames per second in about 42, no background around 50 <span style="background-color:inherit"></span> </span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"> <span style="color:#ff0000; background-color:inherit">update request:</span> </span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">* When the screen needs to be updated, call invalidate ()</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-simple and convenient</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-but will update the entire view, too expensive</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">* It is best to find the invalid zone first and then Call. A more efficient way to do this is to update only the areas that need to be updated</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-invalidate (Rect dirty);</span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5">-invalidate (int left, int top, int. right, int</span></span><span style="line-height:1.5"><span style="line-height:1.5">bottom);</span></span>Window background<span style="background-color:inherit"><span style="background-color:inherit"> </span></span>Update frequency: invalidate transmission about 18 per second, and the last two around 48<span style="color:#ff0000; background-color:inherit"><span style="color:#ff0000; background-color:inherit">views and Layouts:</span></span>* If a window contains many Views-start time long measurement time long layout time long drawing time * If the view tree depth too deep-stackoverflowe Xception user Interface Slow response * Workaround-use TextView's composite drawables to reduce hierarchy-use viewstu b deferred expand view-use <merge> Merge Intermediate view-use relativelayout to reduce levels-use self- Defining views, using custom layouts<span style="background-color:inherit"><span style="background-color:inherit"><span style="color: #ff0000; background-color:inherit"> Memory allocation: </span></span></span>* Do not create Java objects, try to avoid creating Java objects in Performance-sensitive code-measurement: onmeasure ()-layout: onlayout () -drawing: dispatchdraw (), onDraw ()-event handling: dispatchtouchevent (), ontouchevent () -adapter:getview (), BindView () * GC, garbage collection: The entire program will pause, slow (about hundreds of milliseconds * manage good objects * make Best choice of memory cache with soft references * Use weak references to avoid memory leaks<br style="background-color:inherit"> <span style="color:#ff0000; background-color:inherit"><span style="color:#ff0000; background-color:inherit"><span style="background-color:inherit">summary:</span></span></span>* Use Viewholder to achieve Adapter GetView * To select the right image for the background * Update requests for invalid areas * View and layout, the simpler the better * avoid creating on a performance-sensitive path Building objects<span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"><br style="background-color:inherit"></span></span><span style="background-color:inherit; line-height:1.5"><span style="background-color:inherit; line-height:1.5"> </span></span><p><p>Android Interface Optimization Tips</p></p></span>
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