android四种布局管理器 FrameLayout LinearLayout TableLayout RelativeLayout

FrameLayout 帧布局

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView android:layout_width="180dp"
    		android:layout_height="wrap_content"
    		android:background="#000000"
    		 android:textSize="30sp"
       		 android:text="A"
    		/>
    <TextView android:layout_width="160dp"
    		android:layout_height="wrap_content"
    		android:background="#770000"/>
    <TextView android:layout_width="140dp"
    		android:layout_height="wrap_content"
    		android:background="#990000"/>
    <TextView android:layout_width="120dp"
    		android:layout_height="wrap_content"
    		android:background="#DD0000"/>
    
    
</FrameLayout>


LinearLayout线性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="horizontal"
    android:gravity="bottom|center_horizontal"
    >

    <Button  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="按钮1"
             android:gravity="top"
             android:layout_gravity="center_vertical"
        />
    <Button  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="按钮2"
        />
    <Button  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="按钮3"
        />
    <Button  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="按钮4"
        />
    <Button  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="按钮5"
        />
</LinearLayout>


 

TableLayout表格布局

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:stretchColumns="0,1"

    android:collapseColumns="1"
    >

    <!-- 单独的控件会占用单独的一行 -->
     <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮1"
         />
     <!-- 一个TableRow代表一行  TableRow当中的子控件每个控件占一列 -->
     <TableRow  android:layout_width="match_parent"
              android:layout_height="wrap_content"
              
         >
        <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮2"
         />
        <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮3"
         />
    </TableRow> 
     <TableRow  android:layout_width="match_parent"
              android:layout_height="wrap_content"
         >
        <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮4"
         />
        <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮5"
         />
        <Button  android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="按钮6"
         />
        </TableRow> 
</TableLayout>


 

 

RelativeLayout 相对布局

<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="match_parent" >

    
    <EditText  android:id="@+id/nameTxt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:paddingLeft="60dp"
        android:singleLine="true"
    />
    <TextView android:id="@+id/nameLbl"
        android:layout_alignLeft="@id/nameTxt"
        android:layout_alignTop="@id/nameTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="3dp"
        android:textSize="18sp"
        android:text="用户名:"
    />
    <EditText  android:id="@+id/pwdTxt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/nameTxt"
        android:textSize="18sp"
        android:password="true"
        android:paddingLeft="60dp"
        android:singleLine="true"
    />
    <TextView android:id="@+id/pwdLbl"
        android:layout_alignLeft="@id/pwdTxt"
        android:layout_alignTop="@id/pwdTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="3dp"
        android:textSize="18sp"
        android:text="密     码:"
    />
    <Button  android:id="@+id/btn1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="登陆"
         android:layout_below="@id/pwdTxt"
         android:layout_centerHorizontal="true"        
        />
    <Button  android:id="@+id/btn2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="#ff3344"
         android:textSize="15sp"
         android:paddingLeft="5dp"
         android:paddingRight="5dp"
         android:paddingTop="3dp"
         android:paddingBottom="3dp"
         android:text="登陆"
         android:layout_below="@id/btn1"
        />
    
        <Button  android:id="@+id/btn3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn_up"
         android:textSize="15sp"
         
         android:layout_toRightOf="@id/btn2"
         android:layout_alignTop="@id/btn2"
        />
        
        <ImageButton android:id="@+id/btn4"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/btn_up"
         android:adjustViewBounds="true"
         android:padding="0dp"
         android:layout_below="@id/btn2"
            />
        
         <Button  android:id="@+id/btn5"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn"
         android:textSize="15sp"
         
         android:layout_toRightOf="@id/btn4"
         android:layout_alignTop="@id/btn4"
        />
         
         <Button  android:id="@+id/btn5"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn"
         android:textSize="15sp"
         android:layout_below="@id/btn4"
        />
    
</RelativeLayout>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值