Android入門第二篇之LinearLayout、AbsoluteLayout

來源:互聯網
上載者:User

本文來自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>


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.