Android_02_线性布局
来源:互联网 发布:指纹识别算法 源代码 编辑:程序博客网 时间:2024/06/05 17:07
xml文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="5dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" android:orientation="vertical" tools:context=".MainActivity" > <!-- 线性布局:
<span style="white-space:pre"></span>
<span style="white-space:pre"></span>在线性布局中,若没有执行layout的布局方式,则默认的是垂直布局方式 android:gravity:表示组件的内容的对齐方式 android:layout_gravity:表示组件的对齐方式 android:background="#ff0000" 这是指定背景颜色,用#红绿蓝 的方式手动指定 android:background="@android:color/white" @android:color/white这是用系统自带的去指定 你也可以按住ctrl键,再用鼠标点进去,去看起具体的红绿蓝对应的值 布局方向:水平或者竖直 在竖直布局下,左对齐、右对齐,水平居中生效因为在竖直布局下,其进行的是垂直方向的一个分配,所以在水平方向上“左对齐、右对齐,水平居中”可以实现水平方向上的一个调整;在水平布局下,顶部对齐、底部对齐、竖直居中生效因为在水平布局下,其进行的是水平方向的一个分配,所以垂直方向“顶部对齐、底部对齐、竖直居中”可以实现垂直方向上的一个调整;权重:按比例分配屏幕的剩余宽度或者高度在水平布局中,剩余的宽度,是指当我们指定完组件的layout_width之后,所剩下的宽度在水平布局中,剩余的高度,是指当我们指定完组件的layout_height之后,所剩下的高度根据其对应剩下的宽度或高度再按权重去进行分配,所以我们若想实际的效果就是按权重比例分配的话,就建议进行如下设置:在水平布局时,我们一般设置android:layout_width = 0dp在垂直布局时,我们一般设置android:layout_heigt = 0dp这样分配的才是符合权重的比例分配出来的效果 --> <LinearLayout android:paddingBottom="5dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" > <TextView android:layout_weight="1" android:layout_width="0dp" android:background="#ff0000" android:layout_height="match_parent" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:background="@android:color/white" android:layout_height="match_parent" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:background="@android:color/black" android:layout_height="match_parent" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:background="@android:color/darker_gray" android:layout_height="match_parent" /></LinearLayout><LinearLayout android:paddingBottom="5dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="vertical" > <TextView android:layout_weight="1" android:layout_width="match_parent" android:background="#00ff00" android:layout_height="0dp" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:background="@android:color/darker_gray" android:layout_height="0dp" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:background="@android:color/black" android:layout_height="0dp" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:background="#ff0000" android:layout_height="0dp" /> </LinearLayout> </LinearLayout>
实际效果图如下:
0 0
- Android_02_线性布局
- Android_02_相对布局
- Android_02_帧布局
- Android_02_表格布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局
- 线性布局 相对布局 参数
- android布局之线性布局
- android布局之线性布局
- 安卓布局--线性布局
- Android布局之线性布局
- 自定义UICollectionView布局-线性布局
- iOS6新特征:UICollectionView介绍
- TCP/IP和Socket的关系
- CSS学习笔记
- static_cast函数
- grunt和seajs的打包初体验
- Android_02_线性布局
- UICollectionView高级进阶篇
- String的format用法
- PHP mt_srand(),rand(),mt_rand() 函数
- 【干货】100个淘宝电商的专业术语 你造吗
- 2.Android support design NavigationView
- 浏览器兼容性问题
- iOS 最新https遇到的问题
- 链表的创建(头插,尾插),插入,删除