android基本布局

第一种:线性布局

        这种布局相对是比较简单的,要么竖向排列,要么横向排列

 

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  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在CODE上查看代码片派生到我的代码片
 
  1.   

          表格布局:比如几行几列的格式,例如excel的样子

 

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  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在CODE上查看代码片派生到我的代码片
 
  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>  

效果如下:

 

好了,击中常见的布局方式就介绍完了,这些也是自己在看代码的过程中摸索出来的,希望对自己,对别人会有所帮助

posted @ 2015-01-21 20:25  我去ios  阅读(188)  评论(0编辑  收藏  举报