详解四种基本布局 (layout)

1.LinearLayout //线性布局

android:orientation=""  //设置控件的排列方式 horizontal 垂直  vertical 水平
 
<EditText
       android:id="@+id/edit_text"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="1"         //在页面按比例布局
       android:hint="type something"
       />
 
    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="send"
        />
显示:
___【】
 
若改成
<EditText
       android:id="@+id/edit_text"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:hint="type something"
       />    //edit_text会占满剩余屏幕
 
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="send"
        />
显示:
__________【】
 
 
2.RelativeLayout  //相对布局
在页面布局:
android:layout_alignParentLeft+ android:layout_alignParen Top:左上
android:layout_alignParenRight+ android:layout_alignParen Bottom:右下 
android:layout_centerInParent:居中
 
相对控件布局:
//在button3右上
android:layout_above="@id/button3"
android:layout_toRightOf="@id/button3"
 
// 在button3左下
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"
 
//与button3左边缘对齐
android:layout_alignLeft="@id/button3"
//与button3上端对齐
android:layout_alignTop="@id/button3"
 
3.TableLayout  //表格布局
 
<TableLayout 
   。。。
android:stretchColumns="1"   //延伸第二格以填充空白   0表示第一格
>
 
<TableRow>
        <TextView
            android:layout_height="wrap_content"
            android:text="Account:"
            />
        <EditText
            android:id="@+id/account"
            android:layout_height="wrap_content"
            android:hint="Input your account"
           
            />        
    </TableRow>
 
    <TableRow>
        <TextView
            android:layout_height="wrap_content"
            android:text="Password:"
            />
        <EditText
            android:id="@+id/password"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            />
    </TableRow>
 
 
   
    <TableRow>
        <Button
            android:id="@+id/login"
            android:layout_height="wrap_content"
            android:layout_span="2"      //合并单元格
            android:text="login"
            />
    </TableRow>
 
显示:
Account:  ______________
Password:______________
【               login          】
 
2.各控件所占比例可通过 如weightSum="1"(总比例) 和         android:layout_weight="(内填比例)"

 控制

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值