預設的專案中,android已給定一個Relative的界面
上面這個界面很簡單,而裡面包含了3個物件~layout、textview、button
由這個結構可看出RelativeLayout包含了2個物件TextView與Button在裡面
結構簡單表示:
<RelativeLayout
<TextView />
<Button />
/>
以下為它的xml源碼
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
(給定layout一個名稱lay1,而自訂id一定要用@+id/名稱)
android:id="@+id/lay1"
(設定它的寬度 match_parent表示符合父層的寬)
android:layout_width="match_parent"
(設定它的高度 match_parent表示符合父層的高)
android:layout_height="match_parent" >
<TextView
(給定textview一個名稱textView1,而自訂id一定要用@+id/名稱)
android:id="@+id/textView1"
(設定它的寬度 wrap_content表示符合輸入內容的寬)
android:layout_width="wrap_content"
(設定它的高度 wrap_content表示符合輸入內容的高)
android:layout_height="wrap_content"
(alignParentTop代表要以父層的最高處為參考線)
android:layout_alignParentTop="true"
(centerHorizontal代表是否要在水平的中央處)
android:layout_centerHorizontal="true"
(marginTop代表離上邊多遠處,48dp代表距離)
android:layout_marginTop="48dp"
(文字內容可直接寫入,要代入字串則用@string/字串名稱)
android:text="@string/TextView"
(文字的外觀:下面是android預設的字形(大的))
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<Button
(給定textview一個名稱Button1,而自訂id一定要用@+id/名稱)
android:id="@+id/button1"
(設定它的寬度 wrap_content表示符合輸入內容的寬)
android:layout_width="wrap_content"
(設定它的高度 match_parent表示符合父層的高)
android:layout_height="wrap_content"
(alignParentBottom代表要以父層的最底處為參考線)
android:layout_alignParentBottom="true"
(alignParentLeft代表要以父層的左邊為參考線)
android:layout_alignParentLeft="true"
(marginBottom表示要離底部多遠)
android:layout_marginBottom="136dp"
(marginLeft表示要離左邊多遠)
android:layout_marginLeft="37dp"
android:text="@string/Button"
/>
</RelativeLayout>
2012年11月16日 星期五
專案中的結構說明
src:主程式設計的放置處。在裡面會有package,
程式碼都放置在此
gen:最重要的位置,但我們不用去改(也不要亂改)
所有的設定變數,都會在R.java出現
assets:外部的資料、儲存都放置在此
libs:資料庫儲存的位置
res:大部份引用的資源都放置在這裡
drawable:圖片、背景顏色、特效都放在此處
android會預設hdpi、ldpi、mdpi、xldpi
這是預防有此圖片放大後會不好看,因此針對
不同的解析度,放置同名但不同畫質的圖片
layout:設計ui界面
menu:選單的放置處
values:裡面可放置color、string、style、theme
的設定, 現在android形成新專案後會預設
API11(values-v11)及API14(values-v14)的theme
AndroidManifest.xml是很重要的設定,如果這裡出錯
R.java的變數設定會出不來,則程式無法運行
所有的權限設定及多設定的Activiy及Service
都要在這裡寫入
訂閱:
文章 (Atom)