言
android開發真的是讓人覺得很有樂趣的事情呢。比起windows mobile好玩多了。雖然哪個所見即所得的視圖設計環境糟糕的可以。不過這樣用類似描述語言(xml,html)等設計視圖似乎成為了各個技術陣營的首選,WPF也是采用了這樣的方式,描述性文本語言讀起來還是比較舒服的。不過WPF的描述語言過于強大了,讓人有種迷茫的感覺。
先看看今天的成果
效果圖

如果上圖所示,就是簡單的登入界面了。andord的布局真的是,真的是,哪個。難以掌握的東西,哈,不過一旦了解深入點,又讓人爽的不行,流式布局總是比起windows mobile的絕對布局簡單而且容易控制。我是越來越傾向于流式布局的方式了,它的一點好處是适應裝置時比較靈巧,wm使用了自适應dpi的方式,哪叫一個複雜啊,切不易于控制。
先說明的是,線性布局LinearLayout,可真是個重要的東西,它有個方向的屬性,訓示了是水準的或者是垂直的。布局裡有個重要的屬性叫android:background ,指定一個背景圖檔,例如:android:background="@drawable/images1",指定了一個資源檔案的位置。說起這個資源檔案,還是讓我google了一番,不知道怎麼放,後來常識複制粘貼到res下的drawable-hdpi目錄下,居然就能用了。看的教程少,摸索者來吧,高手們才不會指出如此簡單的問題,似吾等.net陣營的小菜用着惱怒的eclipse,而且還沒搞清exlipse的編譯按鈕在那裡,隻知道按下run的人,怎能懂得如此難度的技巧呢。哈,自嘲一把。
回到正題,再說 布局的屬性 android:layout_width="fill_parent" ,訓示了填充父區域,就是父容器有多大空間,就填充多大空間。android:layout_width="wrap_content",訓示了它本身需要多大空間,就像父容器索取多大的空間,怎麼說呢,就是它有多胖就占多大空。而哪個fill_parent就是不胖也全占滿了。
再說android:layout_weight="0.1",這個weight(重量)是個很有意思的東西。可為一個父容器的 “子控件們”設定這個重量屬性,父容器根據這個重量的多少擇情分給這些子控件們多大空間。同時這個屬性還與子控件 寬高屬性的顯示(fill_parent 或者wrap_content)模式有關(影響).
在下來就布局的嵌套了。沒啥說的,類似html裡的div。上代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/images1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.9"></LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/LinearLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout_account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/lblAccount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:text="@string/accountName"
android:textSize="12pt"></TextView>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="mailto:%22 %20android:id=%22@+id/editBoxAccount"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/lblPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:text="@string/password"
android:textSize="12pt"></TextView>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:password="true"
android:text="mailto:%22 %20android:id=%22@+id/editBoxPassword"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="登入"
android:textSize="9pt"></Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
複制
結語
早聞android大名,隻到他墜入貧民級時才接受和了解,而我,還在玩微軟已經放棄了的windows mobile ,.net cf開發,看樣子,為畢業時聽聞的一句話“跟着微軟走,吃喝全都有”,卻不再靈驗。windows phone 7遲遲不見真面目,他面臨的使用者接受程度和開發商支援都是很大的挑戰,而android淪為平民級了,未來還是未知之數,而重量級的xaml語言描述的wcf, silverLight,卻又推廣的不那麼好。總之微軟已經不似幾年前的樣子了,這個龐大的機器狂烈的運轉,卻未帶來更多的技術變革。反而,google。。。