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: