02布局总结

<span style="font-size:18px;">android  有五种布局:
    >Linearlayout  线性布局
    >RelativeLayout  相对布局
    
    >FrameLayout  帧布局
    >TableLayout   表格布局(过时)
    >AbsoluteLayout  绝对布局(过时)  

    4.0以后  新增了一个布局:GridLayout


1,View和ViewGroup
    >View  在UI界面  占矩形界面  
    >ViewGroup  不可见的 容器

    
2.LinearLayout线性布局********
    >概念:单一方向的布局  按水平方向或者垂直方向
    所有子元素 在水平方向或者垂直方向
    每一行或者每一列只能有一个元素

    >属性:
        >1,LinearLayout的方向属性   orientation
          android:orientation:方向属性   有俩个方向  horizontal(水平),vertical(垂直)
          android:orientation="horizontal"
          android:orientation="vertical"
           
          LinearLayout  默认是有方向的      水平方向
                >2,权重属性
            android:layout_weight="1" 权重属性   分配父控件的剩余空间
            剩余空间:父控件的宽或者高  减去  子控件 (所有子元素)的宽或者高 (*和方向有关)
            分配:子控件的宽或者高 = 原有的宽度或者高度  + 剩余空间(宽或者高)/子控件权重的和  *子控件的权重

        note :使用android:layout_weight时设置子控件的宽或者高为0dp(成比例进行分配)

        >3,   android:layout_gravity="bottom"  相对于父控件的位置
                 android:layout_gravity属性和父控件的方向有关
                 如果父控件是水平方向android:layout_gravity的自身的水平方向属性是无效的
                 如果父控件是垂直方向 android:layout_gravity的自身的垂直方向属性是无效的

        >4,android:gravity="bottom|right"
                  如果当前属性是在布局节点:子元素相对于自身的位置
                  如果当前属性在控件中  (button ,TextView..)控制的是控件里的内容   (文字)
    
3.RelativeLayout相对布局*********
    >概念:根据控件的相对位置  进行布局  


    >属性:  16个
        >1,相对于父控件的位置
            
            1,居中位置
             android:layout_centerInParent="true"相对于父控件的中央位置
             android:layout_centerHorizontal="true"相对于父控件的水平居中
             android:layout_centerVertical="true"相对于父控件的垂直居中
            
            水平居中和垂直居中  可以重复使用    
            2,对齐位置
              android:layout_alignParentTop="true"   相对于父控件的  上对齐
              android:layout_alignParentBottom="true" 相对于父控件的  底边对齐
              android:layout_alignParentRight="true" 相对于父控件的  右对齐
              android:layout_alignParentLeft="true"  相对于父控件的  左对齐

        >2,相对兄弟控件的位置
            >1,相对兄弟元素的位置
                android:layout_above="@+id/tv1"   在指定兄弟控件的上边(顶部)
                android:layout_below="@+id/tv1"   在指定兄弟控件的下边(底边)
                android:layout_toLeftOf="@+id/tv1"在指定兄弟控件的左边
                android:layout_toRightOf="@+id/tv1"在指定兄弟控件的右边

            >2, 相对于兄弟控件的对齐方式 :
                android:layout_alignTop="@id/tv_money"  相对指定兄弟控件的顶部对齐
                android:layout_alignBottom="@id/tv_money"相对指定兄弟控件的底部对齐
                android:layout_alignLeft="@id/tv_money"  相对指定兄弟控件的左侧对齐
                android:layout_alignRight="@id/tv_money" 相对指定兄弟控件的右侧对齐
                android:layout_alignBaseline="@id/tv_money"相对指定兄弟控件的基准线对齐
         



了解:

4,Framelayout:帧布局   
    >概念:每个组件都是一帧   当前子组件会覆盖前一个组件

    >属性:
      android:layout_gravity="center"  控制 当前组件的位置
      
          android:foreground="@drawable/ic_launcher"放置在布局管理器所有组件之上
          android:foregroundGravity="top|right"  控制放置的位置  属性可以用"|" 叠加使用  属性不能互斥
    
5,GridLayout:网格布局

     android:orientation="vertical"  排列方式
    
     android:rowCount="3"  行的数量
    android:columnCount="3"列的数量
    
    位置是从0开始
     android:layout_row="0"    控件在第几行展示
     android:layout_column="0" 控件在第几列展示
     
     
     
     android:layout_columnSpan="2"列的跨度
     android:layout_rowSpan="2"  行的跨度
        android:layout_gravity="fill_horizontal"  填充所夸的行和列
        fill   水平和垂直方向都填充
        fill_horizontal  水平方向填充
        fill_vertical    垂直方向填充


4,快捷键:

    shift+ctrl+/   注释
    ctrl+alt+下的方向键   复制
    ctrl+shift+f    格式化代码

5,颜色

    背景  :可以用颜色和图片填充
        颜色:#RGB   #RRGGBB  #AARRGGBB   A代表透明度
        android:background="#ff0000"


6,
    @+id:R文件中没有
        @id :R文件中存在</span>


原文地址:https://www.cnblogs.com/muyuge/p/6152318.html