android:布局、繪製、記憶體泄露、響應速度、listview和bitmap、線程最佳化以及一些最佳化的建議!,androidlistview
1.布局最佳化
首先刪除布局中無用的控制項和層級,其次有選擇地使用效能較低的viewgroup,比如布局中既可以使用RelativeLayout和LinearLayout,那我們就採用LinearLayout,因為RelativeLayout的功能比較複雜,它的布局需要花費
風度哦的CPU實際。
布局最佳化的另一個手段就是採用<include>,<merge>,<viewstub>標籤。<include>主要用於布局重用,<include>,<merge>標籤一般配合使用,他可以減少布局的層級,而<viewstub>澤提供了按需載入的功能,需要
時才會將<viewstub>中的布局載入到記憶體。這提高了程式的初始化效率。下面介紹下他們的使用方法。
<include> :在你的根布局裡面添加<include layout="@layout/main_portals" />就行,然後main_portals布局裡
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hyhotel="http://schemas.android.com/apk/res/com.hysmarthotel.movie" >
//自己按需求添加view
</merge>
注意<include>標籤只支援android:layout開頭的屬性,比如android:layout_width,android:layout_height其他屬性是不支援的如 android:background,android:id是個特例,如果指定了該屬性,同時被包含的布局也指定
了ID,那麼以這個ID為主。如果指定了android:layout_*這種屬性,那麼android:layout_width,android:layout_height就必須存在,否則其他的android:layout_*將無效
<viewstub>:使用方法
<ViewStub
android:id="@+id/hotkey_view_stub"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout="@layout/hotkey_view_layout" />
在你當前的布局裡面添加viewstub,hotkey_view_layout為你需要用到此布局時的名稱,在activity如果要用到這個布局時,有兩種方法載入,當ViewStub被載入時,ViewStub就會被它內部的布局替換掉,這個時候ViewStub就不
再是整個布局的一部分了,而且ViewStub不支援<merge>標籤
(ViewStub)findViewById(R.id.hotkey_view_stub).setVisibility(View,visibie); 或者
ViewStub viewStub = (ViewStub)findViewById(R.id.hotkey_view_stub).inflate();