android布局之线性布局(LinearLayout)
16lz
2021-01-26
LinearLayout 线性布局有两种,分别是水平线性布局和垂直线性布局,LinearLayout属性中android:orientation为设置线性布局当其="vertical"时,为 垂直线性布局,当其="horizontal"时,为水平线性布局,不管是水平还是垂直线性布局一行(列)只能放置一个控件。
下面我们举例说明:
垂直线性布局
[html]- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <EditText
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- />
- <Button
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- android:text="Button1"/>
- <Button
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- android:text="button2"/>
- </LinearLayout>
水平线性布局:
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
- <EditText
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- />
- <Button
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- android:text="Button1"/>
- <Button
- android:layout_width="100dp"
- android:layout_height="wrap_content"
- android:text="button2"/>
- </LinearLayout>
运行结果:
这两种线性布局唯一的差别就是android:orientation的值不同,垂直线性布局的值为vertical,水平线性布局的值为"horizontal"
android线性布局的属性解释
一, linearlayout的属性:android:background 设置整个布局画面的背景
android:orientation="horizontal" 子元素的排列队形,是横向排列,还是纵向排列
android:gravity="bottom" 子元素在布局中的缺省看齐方式
android:padding 设置子元素与布局边缘之间的空白
linearlayout布局的特点是:各个子元素彼此连接,中间不留空白。
二, linearlayout的子元素属性:
android:layout_gravity 设置自身对象在父布局中的看齐方式,可以更新父布局对象gravity属性给出的缺省属性
android:layout_weight 将父布局中剩余的尺寸按各兄弟元素的weight值比例进行填充。与“wrap_content”配合使用即可。
android:layout_margin="10dp" 设置自身对象边缘与父布局的边缘之间的空白
更多相关文章
- View绘制体系(三)——AttributeSet与TypedArray详解
- 全志A40i Android7永不休眠及不锁屏的修改方法
- UI框架之SmartTabLayout使用
- Android(安卓)Support Library-FloatingActionButton
- Android控件复习之TextView与EditText
- Firefox OS 学习——manifest.webapp结构分析
- Activity的属性之―launchMode
- android开发每日汇总【2011-10-04】
- [置顶] Android系统移植与调试之------->build.prop生成过程分析