android:布局、繪製、記憶體泄露、響應速度、listview和bitmap、線程最佳化以及一些最佳化的建議!,androidlistview

來源:互聯網
上載者:User

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();

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.