Androidui Performance Optimization

Source: Internet
Author: User

1, adapter and Adapterview reuse the historical cache (item layout and data cache).

2, data paging display (using operation to guide users)

3, optimize the layout file XML. (layout try not to exceed 5 layers)

4, optimize the activity of the background image. Use Getwindow.setbackgrouddrawable (ID) to set the background map, using the system's default top-level to improve efficiency.

5. Setting the background in a custom theme



6, use Stubview on-demand load, reduce memory consumption



Stubview the layout to load:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout  xmlns:android= "http://schemas.android.com/apk/ Res/android "  android:layout_width=" match_parent "  android:layout_height=" Match_parent "Android:o rientation= "vertical" ><textview android:id= "@android: Id/text1"  android:text= "Portrait Mode"    Android:layout_width= "Wrap_content"    android:layout_height= "wrap_content"/>    <seekbar     android: Id= "@android: id/progress"    android:layout_width= "match_parent" android:layout_height= "Wrap_content"/>    </LinearLayout>

Lazy loading of the main interface:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout  xmlns:android= "http://schemas.android.com/apk/ Res/android "  android:layout_width=" match_parent "  android:layout_height=" match_parent ">  < Button android:id= "@android: Id/button1" android:text= "Load" android:layout_width= "Wrap_content" Android:layout_ height= "Wrap_content"/>  <viewstub android:id= "@+id/stub" android:inflatedid= "@+id/subTree" Android: layout= "@layout/mystub_portrait" android:layout_width= "match_parent" android:layout_height= "Match_parent"/>    </LinearLayout>

Implementation of Stubview Loading

public class Stubviewloadactivity extends Activity {    @Override    protected void OnCreate (Bundle Savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.delay_load);        Button btn = (button) Findviewbyid (Android. R.id.button1);        Btn.setonclicklistener (New Onclicklistener () {            @Override public            void OnClick (View v) {                v.setenabled ( FALSE);                Viewstub stub = (viewstub) Findviewbyid (r.id.stub);                View inflated = Stub.inflate ();}}            );}    }

7. Use child threads and background tasks to complete time-consuming operations



Androidui Performance Optimization

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.