本文來自http://blog.csdn.net/hellogv/
Android 的UI 布局都以Layout 作為容器,在上面按照規定排列控制項,這方面跟JAVA 的Swing 和LWUIT 很像。控制項跟Layout 有很多屬性是一樣的,可以在Properties 裡面修改,跟.NET/Delphi 等RAD 類似,其中最常用的屬性有以下這些:
id="@+id/edtInput",ID 是串連UI 與代碼的橋樑
Gravity= "center" ,Layout 中的控制項置中
layout_width="fill_parent" ,自動填滿至螢幕寬度,layout_height 同理
layout_width="wrap_content" ,自動填滿為控制項大小,layout_height 同理
LinearLayout ,在入門第一篇所用的Layout 就是LinearLayout ,它的理解很簡單:在LinearLayout 裡面的控制項,按照水平或者垂直排列:
orientation="horizontal" :水平排列;orientation=" vertical" :垂直排列
當LinearLayout 是horizontal ,並且裡面的控制項使用了layout_width="fill_parent" ,第二組控制項會擋在螢幕的右邊,那也就是看不到了。。。
AbsoluteLayout ,是一個按照絕對座標定義的布局,由於使用絕對座標去定位控制項,因此要實現自適應介面時,應盡少使用 AbsoluteLayout 。 AbsoluteLayout 裡面的控制項都以layout_x 、layout_y 來定義其位置:
中的TextView01的X座標為10px,Y座標為10px:
<AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" ><br /><TextView android:text="TextView01" android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_y="10px" android:layout_width="wrap_content" android:layout_x="110px"><br /></TextView><br /></AbsoluteLayout>