android基本布局

來源:互聯網
上載者:User

標籤:

第一種:線性布局

        這種布局相對是比較簡單的,要麼豎向排列,要麼橫向排列

 

[html] view plaincopy 
  1. <?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"
    android:padding="10dp">
    <TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Type"/>
    <EditText
    android:id="@+id/et_entry"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hello"
    android:background="#ffffff"/>
    <Button
    android:id="@+id/ok"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/OK"/>
    <Button
    android:id="@+id/cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Cancel"/>
    </LinearLayout>

效果如下:

 

第二種:相對布局

       相對布局:即相對於一個參照物的位置,那麼必須先有參照物,才能確定接下來的控制項的位置,例如先有A,然後B相對於A,在A的右邊、下邊或者什麼位置。當然android中也可以相對於父表單。

 

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  2 xmlns:tools="http://schemas.android.com/tools"  3 android:layout_width="match_parent"  4 android:layout_height="100dp"  5 tools:context=".MainActivity">  6 <TextView 7 android:id="@+id/tv_title"  8 android:layout_width="wrap_content"  9 android:layout_height="wrap_content" 10 android:layout_marginLeft="10dp"11 android:layout_marginTop="10dp" 12 android:textColor="#660000"13 android:textSize="20sp"14 android:text="我是大的文本" /> 15 <TextView 16 android:layout_below="@id/tv_title" 17 android:layout_width="wrap_content" 18 android:layout_height="wrap_content" 19 android:layout_marginLeft="10dp" 20 android:layout_marginTop="10dp" 21 android:textColor="#660000" 22 android:textSize="14sp" 23 android:text="我是小的文本" /> 24 <CheckBox 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:layout_alignParentLeft="true" 28 android:layout_centerVertical="true"29 />30 </RelativeLayout>

 

這個布局如所示:

第三種:表格版面配置

[html] view plaincopy 
  1.   

          表格版面配置:比如幾行幾列的格式,例如excel的樣子

 

[html] view plaincopy 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#000000"  
  6.     android:stretchColumns="1" >  
  7.     <TableRow >  
  8.         <TextView   
  9.             android:text="姓名"  
  10.             android:padding="10dip"  
  11.             android:textColor="#ffffff"/>  
  12.         <EditText   
  13.             android:layout_marginLeft="20dp"  
  14.             android:background="#ffffff"  
  15.             />  
  16.     </TableRow>  
  17.     <TableRow >  
  18.         <TextView   
  19.             android:text="密碼"  
  20.             android:padding="10dip"  
  21.             android:textColor="#ffffff"/>  
  22.         <EditText  
  23.             android:layout_marginLeft="20dp"  
  24.             android:background="#ffffff"  
  25.             android:password="true"   
  26.             />  
  27.     </TableRow>  
  28.   
  29. </TableLayout>  

效果如下:

 



第四種:幀布局

             幀布局:其實比較簡單的理解就是,一個圖片疊加到一個圖片的上面,就是圖片的疊加

 

[html] view plaincopy 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.      >  
  6.     <TextView  
  7.         android:layout_width="match_parent"  
  8.         android:layout_height="match_parent"  
  9.         android:layout_gravity="center"  
  10.         android:background="#ff0000" />  
  11.   
  12.     <TextView  
  13.         android:layout_width="250dp"  
  14.         android:layout_height="390dp"  
  15.         android:layout_gravity="center"  
  16.         android:background="#dd0000" />  
  17.     <TextView  
  18.         android:layout_width="180dp"  
  19.         android:layout_height="300dp"  
  20.         android:layout_gravity="center"  
  21.         android:background="#bb0000" />  
  22.     <TextView  
  23.         android:layout_width="110dp"  
  24.         android:layout_height="210dp"  
  25.         android:layout_gravity="center"  
  26.         android:background="#990000" />  
  27.     <TextView  
  28.         android:layout_width="40dp"  
  29.         android:layout_height="120dp"  
  30.         android:layout_gravity="center"  
  31.         android:background="#770000" />  
  32. </FrameLayout>  

效果如下:

 

好了,擊中常見的布局方式就介紹完了,這些也是自己在看代碼的過程中摸索出來的,希望對自己,對別人會有所協助

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.