Android performance optimization and android Performance Optimization

Source: Internet
Author: User

Android performance optimization and android Performance Optimization

  • Use ViewStub to dynamically load the layout, so that some views that are not often referenced can be held for a long time:

    Some features of ViewStub:
    1. ViewStub can only be Inflate once, and then the ViewStub object is left blank: After a layout specified by ViewStub is Inflate, it will not be enough to control it through ViewStub.
    2. ViewStub can only be used to Inflate a layout file, rather than a specific View. Of course, you can also write the View in a layout file.
    Based on the above features, you can consider using ViewStub:
    1. during the running of the program, a layout after Inflate will not change unless it is restarted.
    Because ViewStub can only be Inflate once and will be left blank later, you cannot expect ViewStub to control the layout later. Therefore, ViewStub cannot display or hide a layout more than once during running. In this case, you can only control the visibility of the View.
    2. To control the display and hiding of a layout file, rather than a View.
    Because ViewStub can only be set to the Id of a layout file, it cannot be used to control a View.

  • Hardware acceleration: android: hardwareAccelerated

 <application        android:name="com.tchip.carlauncher.MyApplication"        android:icon="@drawable/ic_launcher"        android:label="Car Launcher"        android:hardwareAccelerated="true"        android:largeHeap="true"        android:theme="@android:style/Theme.Holo.Light" >
  • View cache: setDrawingCache
    hsvMain = (HorizontalScrollView) findViewById(R.id.hsvMain);    hsvMain.setDrawingCacheEnabled(true);
  • Set the background image of the Window in Acitivity to NULL:
protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);        getWindow().setBackgroundDrawable(null);        setContentView(R.layout.activity_main);        }

The following content:

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.