Android 开发 布局技术

线性布局

垂直布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.1" 
        android:id="@+id/No.1"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.2" 
        android:id="@+id/No.2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.3" 
        android:id="@+id/No.3"
        />

</LinearLayout>




水平布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.1" 
        android:id="@+id/No.1"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.2" 
        android:id="@+id/No.2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.3" 
        android:id="@+id/No.3"
        />

</LinearLayout>
*注意第五行代码的不同



纵横结合

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.1" 
        android:id="@+id/No.1"
        />
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    android:orientation="horizontal">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.2" 
        android:id="@+id/No.2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.3" 
        android:id="@+id/No.3"
        />
    </LinearLayout>

</LinearLayout>


表格布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:shrinkColumns="0,1,2,3,4" >

   <TableRow >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.1" 
        android:layout_column="1"
        android:id="@+id/No.1"
        />
   
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.2" 
        android:layout_column="2"
        android:id="@+id/No.2"
        />
    </TableRow>
    <TableRow >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.3" 
        android:layout_column="2"
        android:id="@+id/No.3"
        />
 	 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.4" 
        android:layout_column="3"
        android:id="@+id/No.4"
        />
 	 </TableRow>
 	 <TableRow >
 	 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.5"
        android:layout_column="3" 
        android:id="@+id/No.5"
        />
 	 </TableRow>
 	 <TableRow >
 	 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.6"
        android:layout_column="4" 
        android:id="@+id/No.6"
        />
 	 </TableRow>
 	 </TableLayout>
</LinearLayout>


相对布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
		android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/enter" 
        />
    <EditText 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/message"
        />
   
    <RelativeLayout
	android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/No.1" 
        android:id="@+id/No.1"
        android:layout_alignParentRight="true"
        />

    <Button
        android:id="@+id/No.2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/No.1"
        android:text="@string/No.2" />

    </RelativeLayout>
  
  


</LinearLayout>



实例:微博登陆界面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff"
    android:orientation="vertical" >
    <RelativeLayout
		android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    >
    <TextView 
        android:text="@string/No.1"
        android:layout_width="200sp"
    	android:layout_height="100sp"
    	android:textSize="40sp"
    	android:textColor="#FF7F00"
    	android:layout_centerHorizontal="true"
    	android:layout_marginTop="20sp"
    	android:gravity="center"
        />
	</RelativeLayout>
	<RelativeLayout
	    android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:orientation="horizontal">
    	<TextView 
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:textColor="#FF7F00"
    	android:text="@string/No.2"
    	android:layout_alignParentLeft="true"
    	android:layout_marginLeft="20sp"
    	android:id="@+id/text1"
    	android:textSize="30sp"
    	 />
    	<EditText 
    	android:layout_width="200sp"
    	android:layout_height="wrap_content"
    	android:layout_marginLeft="100sp"
    	    />
	    
	    
	    
    </RelativeLayout>
    <RelativeLayout
	    android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:orientation="horizontal">
    	<TextView 
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:textColor="#FF7F00"
    	android:text="@string/No.3"
    	android:layout_alignParentLeft="true"
    	android:layout_marginLeft="20sp"
    	android:id="@+id/text1"
    	android:textSize="30sp"
    	 />
    	<EditText 
    	android:layout_width="200sp"
    	android:layout_height="wrap_content"
    	android:layout_marginLeft="100sp"
    	    />
	</RelativeLayout>

    <RelativeLayout
	    android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:orientation="horizontal">
   
   
   
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#CAE1FF"
        android:text="@string/No.5" 
        android:id="@+id/No.5"
        android:layout_alignParentRight="true"
        android:textColor="#FF7F00"
        android:textSize="30sp"
        />
     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#CAE1FF"
        android:text="@string/No.4" 
        android:id="@+id/No.1"
        android:layout_toLeftOf="@id/No.5"
        android:textColor="#FF7F00"
        android:textSize="30sp"
        android:layout_marginRight="10dp"
        />
       </RelativeLayout>
</LinearLayout>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值