Android開發--布局

來源:互聯網
上載者:User

標籤:strong   log   sch   也有   color   表示   wrap   ges   沒有   

一:LinearLayout

     1、線性布局,這個東西,從外框上可以理解為一個div,他首先是一個一個從上往下羅列在螢幕上。每一個LinearLayout裡面又可分為垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )。當垂直布局時,每一行就只有一個元素,多個元素依次垂直往下;水平布局時,只有一行,每一個元素依次向右排列。
  linearLayout中有一個重要的屬性 android:layout_weight="1",這個weight在垂直布局時,代表行距;水平的時候代表列寬;weight值越大就越大。

    2、TextView佔一定的空間,沒有賦值也有一定的寬高,要特別注意。

    第一個執行個體

    :

     

    代碼: 

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >           <LinearLayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         >         <EditText             android:layout_width="fill_parent"             android:layout_height="wrap_content"             />     </LinearLayout>     <LinearLayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:gravity="right"         >     <!-- android:gravity="right"表示Button組件向靠右對齊 -->         <Button             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:text="確定"             />         <Button             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:text="取消"             />         </LinearLayout> </LinearLayout> 

    第二個執行個體:

     :

       

     代碼:     

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    ><TextView    android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="5"    android:background="#3C3C3C" /><TextView    android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="1"    android:background="#FFEFD5"     /> <LinearLayout             android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="4"            android:background="#66CDAA"            android:orientation="horizontal"            >                          <TextView                 android:id="@+id/txt1"                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:background="#FFF663"                android:layout_weight="1"                 />             <TextView                 android:id="@+id/txt2"                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:background="#E82917"                android:layout_weight="4"                                 />              <TextView                 android:id="@+id/txt3"                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:background="#FFF663"                android:layout_weight="1"                               />                      </LinearLayout></LinearLayout>

    我們要做的就是多多實踐,多看下關於軟體的布局。軟體上的布局和真機上的布局有差異,我們儘可能的拿真機去測驗,並且在不同的機型上去測驗。

 

 

Android開發--布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.