布局的学习

LinearLayout
       线性布局
            线性布局中的子容器或控件,按先后顺序水平或垂直的排列
      主要属性
              android:orientation
     android:layout_weight
      主要方法:
          addView()


 android:layout_weight
TableLayout
           表格布局
         继承自LinerLayout
 控件垂直线性排列,默认宽度填充整行,高度适应内容
 常与TableRow配合使用
  主要属性
         android:collapseColumns
 android:stretchColumns
 android:shrinkColumns
 TableRow
          继承自LinearLayout
  控件水平线性排列,默认高度,宽度适应内容
相对布局RelativeLayout
             相对布局的节点名称为RelativeLayout
    相对布局是一种使用已有的控件为参考点,确定新的控件的位置的布局模式
          使用相对布局时,其同级的控件允许设置如下属性:
     1,layout_below/layout_above:位于某控件下面/上面,取值为参考点控件id;
     2,layout_toLeftOf/layout_toRightOf:位于某控件左侧或右侧,取值为参考点控件id;
     3,layout_alignLeft/layout_alignTop/layout_alignBottom/layout_alignRight:
         与某控件的左侧/顶部/底部/右侧对齐,取值为参考点控件id;
     4,layout_alignBaseline:与某控件的基线对齐,取值为参考点控件id;
     5,layout_alignParentLeft/layout_alignParentTop/layout_alignParentRight/layout_alignParentBottom:
          与父级的左侧/右侧/底部/对齐,取值为true或false;
    6,layout_centerlnParent/layout_centerHorizontal/layout_centerVertical:

             在父级中居中/垂直居中,取值为true,false;


布局实现简单的计算机界面:

        

<GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:columnCount="4"
     android:rowCount="6">
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="3.1415926"
        android:layout_columnSpan="4"
        />
    
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="*"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="/"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DEL"/>
     <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AC"/>
     <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="7"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="9"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-"/>
    <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"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        android:layout_rowSpan="2"
        android:layout_gravity="fill_vertical"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"/>
    <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="0"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="."/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="="
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"/>
</GridLayout>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值