前言
android開(kāi)發(fā)真的是讓人覺(jué)得很有樂(lè)趣的事情呢。比起windows mobile好玩多了向瓷。雖然哪個(gè)所見(jiàn)即所得的視圖設(shè)計(jì)環(huán)境糟糕的可以业踢。不過(guò)這樣用類似描述語(yǔ)言(xml,html)等設(shè)計(jì)視圖似乎成為了各個(gè)技術(shù)陣營(yíng)的首選,WPF也是采用了這樣的方式嗽冒,描述性文本語(yǔ)言讀起來(lái)還是比較舒服的呀伙。不過(guò)WPF的描述語(yǔ)言過(guò)于強(qiáng)大了,讓人有種迷茫的感覺(jué)添坊。
先看看今天的成果
效果圖
如果上圖所示剿另,就是簡(jiǎn)單的登錄界面了。andord的布局真的是贬蛙,真的是雨女,哪個(gè)。難以掌握的東西阳准,哈氛堕,不過(guò)一旦了解深入點(diǎn),又讓人爽的不行野蝇,流式布局總是比起windows mobile的絕對(duì)布局簡(jiǎn)單而且容易控制讼稚。我是越來(lái)越傾向于流式布局的方式了括儒,它的一點(diǎn)好處是適應(yīng)設(shè)備時(shí)比較靈巧,wm使用了自適應(yīng)dpi的方式锐想,哪叫一個(gè)復(fù)雜啊帮寻,切不易于控制。
先說(shuō)明的是赠摇,線性布局LinearLayout固逗,可真是個(gè)重要的東西,它有個(gè)方向的屬性藕帜,指示了是水平的或者是垂直的烫罩。布局里有個(gè)重要的屬性叫android:background ,指定一個(gè)背景圖片,例如:android:background="@drawable/images1"耘戚,指定了一個(gè)資源文件的位置嗡髓。說(shuō)起這個(gè)資源文件,還是讓我google了一番收津,不知道怎么放饿这,后來(lái)常識(shí)復(fù)制粘貼到res下的drawable-hdpi目錄下,居然就能用了撞秋〕づ酰看的教程少,摸索者來(lái)吧吻贿,高手們才不會(huì)指出如此簡(jiǎn)單的問(wèn)題串结,似吾等.net陣營(yíng)的小菜用著惱怒的eclipse,而且還沒(méi)搞清e(cuò)xlipse的編譯按鈕在那里舅列,只知道按下run的人肌割,怎能懂得如此難度的技巧呢。哈帐要,自嘲一把把敞。
回到正題,再說(shuō) 布局的屬性 android:layout_width="fill_parent" 榨惠,指示了填充父區(qū)域奋早,就是父容器有多大空間,就填充多大空間赠橙。android:layout_width="wrap_content"耽装,指示了它本身需要多大空間,就像父容器索取多大的空間期揪,怎么說(shuō)呢掉奄,就是它有多胖就占多大空。而哪個(gè)fill_parent就是不胖也全占滿了横侦。
再說(shuō)android:layout_weight="0.1"挥萌,這個(gè)weight(重量)是個(gè)很有意思的東西绰姻。可為一個(gè)父容器的 “子控件們”設(shè)置這個(gè)重量屬性引瀑,父容器根據(jù)這個(gè)重量的多少擇情分給這些子控件們多大空間狂芋。同時(shí)這個(gè)屬性還與子控件 寬高屬性的顯示(fill_parent 或者wrap_content)模式有關(guān)(影響).
在下來(lái)就布局的嵌套了。沒(méi)啥說(shuō)的憨栽,類似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>
結(jié)語(yǔ)
早聞android大名,只到他墜入貧民級(jí)時(shí)才接受和了解屑柔,而我屡萤,還在玩微軟已經(jīng)放棄了的windows mobile ,.net cf開(kāi)發(fā),看樣子掸宛,為畢業(yè)時(shí)聽(tīng)聞的一句話“跟著微軟走死陆,吃喝全都有”,卻不再靈驗(yàn)唧瘾。windows phone 7遲遲不見(jiàn)真面目措译,他面臨的用戶接受程度和開(kāi)發(fā)商支持都是很大的挑戰(zhàn),而android淪為平民級(jí)了饰序,未來(lái)還是未知之?dāng)?shù)领虹,而重量級(jí)的xaml語(yǔ)言描述的wcf, silverLight,卻又推廣的不那么好求豫∷ィ總之微軟已經(jīng)不似幾年前的樣子了,這個(gè)龐大的機(jī)器狂烈的運(yùn)轉(zhuǎn)蝠嘉,卻未帶來(lái)更多的技術(shù)變革最疆。反而,google蚤告。肚菠。。