2014年2月20日 星期四

[Layout][Performance]

<merge>:
減少佈局層次達到優化佈局的效果。


※android:layout_gravity  :設定靠左右、置中 | 靠上下
※android:layout_marginBottom :物件的位置



<merge xmlns:android="http://schemas.android.com/apk/res/android" >
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="1" >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="60dip"
        android:text="delete" />


    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:text="add" />

</merge>
使用Merge 少了一層layout


<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="1" >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="delete" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_gravity="center_horizontal|top"
        android:layout_row="1"
        android:text="add" />

</GridLayout>

此圖沒使用Merge,多一層GridLayout






//--------------------------------------------------------------------------------------------------
ViewStub:
ViewStub默認是View.GONE,這樣在通常情況下不是會顯示出來的,只有當用到時,再把它顯示出來。

※ViewStub目前有个缺陷就是还不支持 <merge /> 标签。

http://mobile.51cto.com/abased-376576.htm

http://www.cnblogs.com/menlsh/archive/2013/03/17/2965217.html

注意:inflate()函数返回解析后的View,所以你没有必要在调用函数findViewById()来得到这个View。這個ViewStub就不在界面層級結構中了,被鎖引用的佈局替代了,新的ID是ViewStub的屬性的android:inflatedId中設置的值。

沒有留言:

張貼留言