国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
AndroidUI優(yōu)化4

Android UI 優(yōu)化4收藏



有一句古話:不論黑貓白貓,能抓到耗子就是好貓。這個也許在某些方面是有道理的,但對于我們追求精益求精的思想是背道而馳的,往往就是因為滿足于一個結(jié)果,而放棄探求更加優(yōu)化的處理方法。

當(dāng)關(guān)注應(yīng)用程序或者游戲所達到的結(jié)果時,往往非常容易忽視一些優(yōu)化的問題,例如內(nèi)存優(yōu)化,線程優(yōu)化,Media優(yōu)化和UI優(yōu)化等等。不同的模塊都存在更為巧妙的方式來對待一般性問題,所以每當(dāng)我們實現(xiàn)一個行為后,稍微多花一些時間來考慮目前所作的工作是否存在更為高效的解決辦法。
這一次我們對常用的UI Layout優(yōu)化說起,這個例子轉(zhuǎn)載于 android developing blog
Android中最常用LinearLayout表示UI的框架,而且也是最直觀和方便的方法。例如創(chuàng)建一個UI用于展現(xiàn)Item的基本內(nèi)容。如圖所示:

 

 

直接可以通過LinearLayout快速的實現(xiàn)這個UI的排列:



View Code XML
<LinearLayout xmlns:
    android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"

    android:padding="6dip">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"

        android:src="@drawable/icon" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"

            android:gravity="center_vertical"
            android:text="My Application" />

        <TextView  
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" 

            android:singleLine="true"
            android:ellipsize="marquee"
            android:text="Simple application that shows how to use RelativeLayout" />

    </LinearLayout>

</LinearLayout>

盡管可以通過Linearlayout實現(xiàn)我們所預(yù)想的結(jié)果,但是在這里存在一個優(yōu)化的問題,尤其是針對為大量Items。比較RelativeLayout和LinearLayout,在資源利用上前者會占用更少的資源而達到相同的效果,以下是用RelativeLayout實現(xiàn)的代碼:



View Code XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"

    android:padding="6dip">

    <ImageView
        android:id="@+id/icon"

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="6dip"

        android:src="@drawable/icon" />

    <TextView  
        android:id="@+id/secondLine"

        android:layout_width="fill_parent"
        android:layout_height="26dip" 

        android:layout_toRightOf="@id/icon"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"

        android:singleLine="true"
        android:ellipsize="marquee"
        android:text="Simple application that shows how to use RelativeLayout" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_toRightOf="@id/icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_above="@id/secondLine"
        android:layout_alignWithParentIfMissing="true"

        android:gravity="center_vertical"
        android:text="My Application" />

</RelativeLayout>

針對RelativeLayout有一點需要注意,因為它內(nèi)部是通過多個View之間的關(guān)系而確定的框架,那么當(dāng)其中某一個View因為某些需要調(diào)用GONE來完全隱藏掉后,會影響與其相關(guān)聯(lián)的Views。Android為我們提供了一個屬性 alignWithParentIfMissing 用于解決類似問題,當(dāng)某一個View無法找到與其相關(guān)聯(lián)的Views后將依據(jù)alignWithParentIfMissing的設(shè)定判斷是否與父級View對齊。


下邊是兩種不同layout在Hierarchy Viewer中的層級關(guān)系圖:


本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android 設(shè)置頁面UI設(shè)計
淺談Android五大布局
Android 五大布局講解與應(yīng)用 – 碼農(nóng)網(wǎng)
LinearLayout和RelativeLayout 比較
Android:自定義Tab樣式
新浪微博布局學(xué)習(xí)——活用RelativeLayout
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服