LinearLayout 线性布局有两种,分别是水平线性布局和垂直线性布局,LinearLayout属性中android:orientation为设置线性布局当其="vertical"时,为 垂直线性布局,当其="horizontal"时,为水平线性布局,不管是水平还是垂直线性布局一行(列)只能放置一个控件。

下面我们举例说明:

垂直线性布局

[html]
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical">
  6. <EditText
  7. android:layout_width="100dp"
  8. android:layout_height="wrap_content"
  9. />
  10. <Button
  11. android:layout_width="100dp"
  12. android:layout_height="wrap_content"
  13. android:text="Button1"/>
  14. <Button
  15. android:layout_width="100dp"
  16. android:layout_height="wrap_content"
  17. android:text="button2"/>
  18. </LinearLayout>


运行的结果:


水平线性布局:


[html]
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="horizontal">
  6. <EditText
  7. android:layout_width="100dp"
  8. android:layout_height="wrap_content"
  9. />
  10. <Button
  11. android:layout_width="100dp"
  12. android:layout_height="wrap_content"
  13. android:text="Button1"/>
  14. <Button
  15. android:layout_width="100dp"
  16. android:layout_height="wrap_content"
  17. android:text="button2"/>
  18. </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" 设置自身对象边缘与父布局的边缘之间的空白

更多相关文章

  1. View绘制体系(三)——AttributeSet与TypedArray详解
  2. 全志A40i Android7永不休眠及不锁屏的修改方法
  3. UI框架之SmartTabLayout使用
  4. Android(安卓)Support Library-FloatingActionButton
  5. Android控件复习之TextView与EditText
  6. Firefox OS 学习——manifest.webapp结构分析
  7. Activity的属性之―launchMode
  8. android开发每日汇总【2011-10-04】
  9. [置顶] Android系统移植与调试之------->build.prop生成过程分析

随机推荐

  1. Android开发中出现Attempt to invoke vir
  2. Android 入门知识点梳理之一 四大组件
  3. Android(安卓)之Content Provider(URI)存储
  4. 初学Android,开机自启动的Service(七十三
  5. Android Jetpack组件学习 ViewModel & Li
  6. android读取properties配置文件
  7. android手势翻页效果【转】
  8. 花样Android ProgressBar 史上最强大讲解
  9. Android常用的15个框架
  10. Android(安卓)camera 默认显示黑白的问题