常用的五大布局

常用的五大布局(线性布局,相对布局,帧布局,表格布局,绝对布局)

1,线性布局    LinearLayout

<LinearLyout
    android:layout_width="wrap_content"         //包裹内容
    android:layout_height="match_parent"       //填充父窗体
    android:orientation="vertical">                  //horizontal:  水平   vertical:垂直
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="我是按钮01"
        />
</LinearLyout> 

orientation:朝向:
weight: 权重    ,控制空间在父窗体里面显示的比例

计算器的原型图

2.相对布局    RelateLayout

<RelativeLayout
        android:layout_width=" wrap_content "
        android:layout_height=" wrap_content ">
             <Button
                    android:id="@+id/bt_middle"      //ID名字
                    //android:layouot_centerInParent="true"  //相对父控件居中   等同于下面两句
                    android:layout_centerHorizontal="true"  //控件水平居中
                    android:layout_centerVertical="true"   //控件垂直居中
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="中间"   />
              <Button
                android:layout_width="wrap_centnet"
                android:layout_height="wrap_centnet"
                android:layout_above="@+id/bt_middle"   //相对于某个控件的上方
                android:layout_centerHorizontal="true"   //水平居中
                android:text="↑"/>
</RelativeLayout>

        android:layout_above="@+id/bt_middle"            //相对于某个控件的上方        android:layout_below="@id/bt_middle"             //相对于某个控件下方        android:layout_toLeftOf="@id/bt_middle"         //相对于某个控件的左方        android:layout_toRightOf="@id/bt_middle"      //相对于某个控件的右方android:layout_alignParentTop="true"         //与父窗体的上边角对齐        android:layout_alignParentLeft="true"        //与父窗体的左边角的对齐        android:layout_alignParentBottom="true"  //与父窗体的下边角对齐        android:layout_alignParentRight="true"      //与父窗体的右边角对齐

3.帧布局    FrameLayout

类似>div    层叠布局

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >    
                <TextView
                         android:layout_width="300px"                                android:layout_height="300px"
                          android:layout_gravity="center"
                          android:backgroud="#ff00"   />
                 <TextView
                          android:layout_width="200px"                                android:layout_height="200px"                                                                                                     android:layout_gravity="center"                       
                          android:backgroud="#0ff"     />            
</FrameLayout>

运行结果为:

表格布局和绝对布局用的特别少.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值