Android中常用的布局

第一种:线性布局

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



<?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="10px">
    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type:"/>
    <EditText 
        android:id="@+id/et_entry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"/>
    <Button 
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/et_entry"
        android:text="OK"/>
    <Button 
        android:id="@+id/cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
      	android:text="Cancel"/>
</LinearLayout>


第二种:相对布局

       相对布局:即相对于一个参照物的位置,那么必须先有参照物,才能确定接下来的控件的位置,例如先有A,然后B相对于A,在A的右边、下边或者什么位置。当然android中也可以相对于父窗体



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="100px"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10px"  <span style="font-family: Arial, Helvetica, sans-serif;">/*距离父窗体的左边10个像素*/</span>
        android:layout_marginTop="10px"   <span style="font-family: Arial, Helvetica, sans-serif;">/*距离父窗体的顶部10个像素*/</span>
        android:textColor="#660000"       /*控件上显示文本的颜色RGB*/
        android:textSize="20px"           /*控件上显示文本的字体大小*/
        android:text="我是大的文本" />
	<TextView
        android:layout_below="@id/tv_title"    /*当前控件位于tv_title这个控件的下方*/
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10px"
        android:layout_marginTop="10px"
        android:textColor="#660000"
        android:textSize="14px"
        android:text="我是小的文本" />
	<CheckBox 
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_alignParentRight="true"    /*当前控件与父窗体的右边对齐*/
	    android:layout_centerVertical="true"      /*当前控件在父窗体的竖直中心位置*/
	    />
</RelativeLayout>


第三种:表格布局




<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:stretchColumns="1" >
    <TableRow >
        <TextView 
            android:text="姓名"
            android:padding="10dip"
            android:textColor="#ffffff"/>
        <EditText 
            android:layout_marginLeft="20dp"
            android:background="#ffffff"
            />
    </TableRow>
    <TableRow >
        <TextView 
            android:text="密码"
            android:padding="10dip"
            android:textColor="#ffffff"/>
        <EditText
            android:layout_marginLeft="20dp"
            android:background="#ffffff"
            android:password="true" 
            />
    </TableRow>

</TableLayout>


第四种:帧布局

             帧布局:其实比较简单的理解就是,一个图片叠加到一个图片的上面,就是图片的叠加


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	 >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="#ff0000" />

	<TextView
	    android:layout_width="250dp"
	    android:layout_height="390dp"
	    android:layout_gravity="center"
	    android:background="#dd0000" />
	<TextView
	    android:layout_width="180dp"
	    android:layout_height="300dp"
	    android:layout_gravity="center"
	    android:background="#bb0000" />
	<TextView
	    android:layout_width="110dp"
	    android:layout_height="210dp"
	    android:layout_gravity="center"
	    android:background="#990000" />
	<TextView
	    android:layout_width="40dp"
	    android:layout_height="120dp"
	    android:layout_gravity="center"
	    android:background="#770000" />
</FrameLayout>



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值