常见布局管理器笔记小结

1、线性布局

LinearLayout:控制子控件按照横向纵向排列
1. 灵魂属性:android:orientation=”vertical”;(horizontal)
2. gravity属性:控制布局内所有子控件在父容器中的相对位置
-center 水平垂直居中(在中央)
-center_horizontal 水平居中
-center_vertical 垂直居中
-top 顶部
-bottom 底部
-left 靠左
-right 靠右

2、相对布局

RelativeLayout:子控件灵活的出现在某特殊的位置上;方便描述控件与控件的位置
1. 根据父容器定位
2. 根据兄弟控件定位
3. margin(偏移):设置组件与父容器之间的边距
4. padding(填充):控件内部元素间的边距(比如TextView内部字体的位置)

3、帧布局

FrameLayout:子控件之间是层叠覆盖的关系;多应用在滑动页和碎片出现的场合
1. android:foreground: 设置次帧布局容器的前景图像
2. android:foregroundGravity: 设置前景图像显示的位置

4、表格布局

TableLayout:确定表格的行数;设置某一行中某列元素 隐藏 拉伸收缩
1. android:collapseColumns:设置需要被隐藏的列的序号
2. android:shrinkColumns:设置允许被收缩的列的列序号
3. android:stretchColumns:设置运行被拉伸的列的列序号

5、网格布局

GridLayout
1. 设置排列方式
2. 设置几行几列
android:rowCount;网格布局中的行数
android:columnCount; 网格布局中的列数
3. 设置组件所在的行列
4. 设置组件横跨几行几列

关键点一、android:gravity vs android:layout_gravity

  1. android:gravity设置布局内部所以的子View
  2. android:layout_gravity设置View本身
  3. 在线性布局中android:layout_gravity属性的设置与父布局的
    android:orientation有关
  4. 当 android:orientation=”vertical” 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。 即:left,right,center_horizontal 是生效的。 当 android:orientation=”horizontal” 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。 即:top,bottom,center_vertical 是生效的

关键点二、layout_weight权重属性

  1. 在线性布局中:若布局灵魂属性为横向,在子控件中将(宽)
    设置为0dp(android:layout_width=”0dp”),相对最外层布局则会按照权重属性分配剩余空间。纵向排列同理。
  2. 根据orientation属性,比如是横向的,在设置View宽度属性为包裹内容,即android:layout_width=”wrap_content” ,则相对最外层布局则会按照权重属性分配剩余空间,借鉴代码,加强理解。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:id="@+id/LinearLayout1"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"  
    android:orientation="horizontal" >    

    <TextView    
        android:layout_weight="1"    
        android:layout_width="wrap_content"    
        android:layout_height="fill_parent"    
        android:text="one"     
        android:background="#98FB98"    
     />    
     <TextView    
        android:layout_weight="2"    
        android:layout_width="wrap_content"    
        android:layout_height="fill_parent"    
        android:text="two"     
        android:background="#FFFF00"    
     />    
     <TextView    
        android:layout_weight="3"    
        android:layout_width="wrap_content"    
        android:layout_height="fill_parent"    
        android:text="three"     
        android:background="#FF00FF"    
     />    

</LinearLayout>

3.如果设置
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” 属性,则需要重新计算,计算依据为权重每次分的是父容器的剩余空间(不论是纵向还是横向)

关键点三、为LinearLayout设置分割线

  1. 直接添加一条线的View,代码如下
<View  
    android:layout_width="match_parent"  
    android:layout_height="1px"  
    android:background="#000000" /> 

2.LinearLayout的一个divider属性

夜深人静。。。。。。。。。。sleep

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值