LinearLayout(线性布局)
来源:互联网 发布:7405单片机管脚图 编辑:程序博客网 时间:2024/06/06 03:18
基本属性
orientation
布局中组件的排列方式,有horizontal(水平),vertical(竖直 默认),两种方式。
gravity
控制组件所包含的子元素的对齐方式,可以多个组合。
layout_width
布局的宽度,通常不会直接设置,而是采用wrap_content(组件的实际大小),fill_parent或者match_parent填满父容器。
layout_height
布局的高度。
background
为该组件设置一个背景图片或者设置背景颜色。
weight属性
1.layout_width=”0dp”
在下的子元素中(例如等),将layout_width设置为”0dp”,直接通过layout_weight来划分比例设置宽度,比例的划分根据layout_weight所占权重大小。
按比例划分水平方向:将涉及到的View的android:width属性设置为0dp,然后设置为android weight属性设置比例即可;类推,竖直方向,只需设android:height为0dp,然后设weight属性即可!
2.layout_width=”wrap_content”
同样通过设置子元素的layout_weight属性来划分比例设置宽度
3.match_parent(fill_parent)
这种方法下的设置需要通过计算,显示出来的结果并不直观。
计算技巧:
step 1:个个都是fill_parent,但是屏幕只有一个,那么1 - 3 = - 2 fill_parent steps 2:依次比例是1/6,2/6,3/6 step 3:先到先得,先分给one,计算: 1 - 2 * (1/6) = 2/3 fill_parent 接着到two,计算: 1 - 2 * (2/6) = 1/3 fill_parent 最后到three,计算 1 - 2 * (3/6) = 0 fill_parent step 4:所以最后的结果是:one占了两份,two占了一份,three什么都没有。
为LinearLayout设置分割线
1.通过标签直接添加
<View android:layout_width="match_parent" android:layout_height="1px" android:background="#000000" />
2.借用LinearLayout的一个divider属性
需要你准备一张线的图片了 1)android:divider设置作为分割线的图片 2)android:showDividers设置分割线的位置,none(无),begining(开始),end(结束),middle(每两个组件间) 3)dividerPadding设置分割线的Padding
android:divider="@drawable/ktv_line_div" android:orientation="vertical" android:showDividers="middle" android:dividerPadding="10dp"
当 android:orientation=”vertical” 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。 即:left,right,center_horizontal 是生效的。 当 android:orientation=”horizontal” 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。 即:top,bottom,center_vertical 是生效的。
本文整理转载出处
- 线性布局(LinearLayout)
- LinearLayout(线性布局)
- LinearLayout(线性布局)
- Android--LinearLayout(线性布局)
- Android LinearLayout(线性布局)
- Android-线性布局(LinearLayout)
- Android布局之LinearLayout(线性布局)
- Android布局之LinearLayout(线性布局)
- Android布局之LinearLayout(线性布局)
- Android:控件布局(线性布局)LinearLayout
- android布局之Linearlayout(线性布局)
- Android中的线性布局(LinearLayout)
- Android线性布局LinearLayout(七)
- Android UI之LinearLayout(线性布局)
- Android 线性布局(LinearLayout)性能相关
- LinearLayout (线性布局)的分析
- Android第二天 线性布局(LinearLayout)
- Android 线性布局:LinearLayout
- 关于Android的四种启动模式
- Html 学习二
- 排列若干个字符串,判断是否首尾可以连接在一起
- 用shell脚本监控进程是否存在 不存在则启动的实例
- 树莓派调整分区大小
- LinearLayout(线性布局)
- CodingNet - Learning - 18
- 单例模式(饿汉式和懒汉式)
- Android SQLite数据库的基本使用
- Linux分页机制之概述--Linux内存管理(六)
- 自己写的《带着媳妇去冒险》安卓手游
- java 代理模式,JDK动态代理,SpringAOP的实现
- **高精度模板**
- git入门简单介绍