標籤:android style blog http color io 使用 ar 檔案
簡介
在Android官網中有對UI 最佳化的文檔,開發人員有必要對它進行掌握。
詳解1、抽象布局
<include />標籤能夠重用布局檔案
<include layout="@layout/titlebar"/>
<merge/>標籤可以刪減多餘的層級,它多用於替換FrameLayout或者當一個布局包含另一個時,消除視圖階層中多餘的視圖組
<merge xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/add"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/delete"/> </merge>
<ViewStub />標籤使用它的優點是需要時才會載入,它並不會影響UI初始化時的效能。各種不常用的布局都可以使用<ViewStub />標籤,以減少記憶體使用量量,加快渲染速度。
<ViewStub android:id="@+id/stub_import" android:inflatedId="@+id/panel_import" android:layout="@layout/progress_overlay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" />
2、Android樣式和主題
android中的樣式是用於為介面元素定義顯示風格,它是一個包含一個或者多個view控制項屬性的集合。
Android 允許在外部樣式檔案中定義 Android 應用程式的 Look 和 Feel ,你可以將定義好的樣式應用在不同的視圖(Views)上。你可以在 XML 檔案中定義樣式,並將這些樣式運用到不同的組件上。使用XML這種方式定義樣式,你只需要配置一些通用的屬性,以後如果需要修改樣式,可以集中修改。
你可以在你 Android 項目的 /res/values 檔案下建立一個 XML 檔案,注意給檔案的根目錄必須是 <resources>。下面的例子將展示在 /res/xml目錄下建立 style.xml 檔案。
定義和使用如下:
<?xml version="1.0" encoding="utf-8"?><resources> <style name=“itcast”> <!-- 為樣式定義一個全域唯一的名字--> <item name="android:textSize">18px</item> <!-- name屬性為樣式要用在的View控制項持有的屬性 --> <item name="android:textColor">#0000CC</item> </style></resources>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" .> <TextView style="@style/itcast" .. /></LinearLayout>
主題是針對應用中所有Activity或者針對某個Activity設定樣式,可以通過編輯AndroidManifest.xml來完成。
主題相比單個視圖而言,是應用到整個 Activity 或者 application 的樣式。下面例子將自訂一個主題,該主題將繼承 Android 定義好的主題。
定義和使用如下:
<activity android:theme="@style/wrap_content">
<activity android:theme="@android:style/Theme.Dialog">
3、ViewFlipper
它的作用是什麼呢,就是一個簡單的ViewAnimator,將添加到ViewFlipper的View形成動畫。但是在一個時間點只要一個View顯示。當然,也可以設定讓動畫自動的有規律的顯示。
4、Fragment架構
什麼是Fragment?Fragment是一個片段,寄生於Activity的上下文中,Fragment擁有一個與它相關的視圖階層,擁有一個與活動非常相似的生命週期。
Fragment的作用是什嗎?Activity有一個局限,不能將多個Activity活動介面放在螢幕上一併顯示。因此建立了Fragment來彌補Activity的局限。Fragment可以像Activity一樣響應Back鍵等類似Activity的功能。
Fragment的生命週期
Android 進階UI