一、布局概述:

  布局为UI提供了一个可视化的结构,比如对于一个activity或者app widget的UI,你可以用两种方式声明布局:

      在XML中声明UI元素

      在运行时实例化布局元素(在java代码中去写布局)

  布局之间可以相互嵌套

二、LinearLayout概述:

  LinearLayout是线性布局控件,它包含的子控件将横向或竖向的方式排列

三、LinearLayout属性:

  1、android:orientation = ""

          该属性决定他子类控件的排布方式(vertical:垂直;horizontal:水平)

  2、android:gravity = ""

        该属性决定他所有子类的xy的位置,多个属性可以一起用(android:gravity="bottom|right"),常用到的几个属性值:

          center_vertical:垂直(Y抽居中)

          center_horizontal:水平(X抽居中)

          center:水平垂直都居中

          right:子类控件位于当前布局的右边

          left:子类控件位于当前布局的左边

          bottom:子类控件位于当前布局的下面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom|right" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> </LinearLayout>

  3、子类控件在LinearLayout中常用到的属性

    android:layout_gravity = "bottom"  ------指本身在当前父容器的XY的一个位置,这个属性注意的地方:

        这个属性的属性值跟android:gravity = ""是一样的

        有时候这个属性达不到你想要的效果,那么就用布局中的android:gravity = ""去控制

        需要结合线性布局中的android:orientation="vertical"属性一起使用,这个属性的值不同会有不同的效果

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:layout_gravity="center_horizontal"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> </LinearLayout>

    android:layout_weight = "1" -------指本身控件占当前父容器的一个比例

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" /> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" /> </LinearLayout>

四、布局的嵌套

  布局之间可以嵌套,就是一个布局里面可以在加多一个或多个布局(任意布局都可以,线性布局也可以嵌套相对布局)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" /> </LinearLayout> </LinearLayout>

Android布局_布局概述和LinearLayout布局的更多相关文章

  1. Android学习——LinearLayout布局实现居中、左对齐、右对齐

    android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...

  2. [android]如何使LinearLayout布局从右向左水平排列,而不是从左向右排列

    方法1: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:l ...

  3. Android:LinearLayout布局中Layout_weight的深刻理解

    首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重.很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间. 看下面代码 ...

  4. 【Android UI】Android开发之View的几种布局方式及实践

    引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...

  5. Android 开发:view的几种布局方式及实践

    View的几种布局显示方法,以后就不会在针对布局方面做过多的介绍.View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Tab ...

  6. Android开发:View的几种布局及实践

    引言 View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Table Layout).网格视图(Grid View).标签布 ...

  7. Android新手入门2016(7)--布局

    布局,这个在服务端变成是没有的,也是服务端的人学习client的一道坎吧. 曾经用cocos2d-x写小游戏的时候就是这个非常难懂,或者能用,可是理解不多的话,非常难写出好的布局,难以适合商业化的应用 ...

  8. 三、Android学习第三天——Activity的布局初步介绍(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 三.Android学习第三天——Activity的布局初步介绍 今天总结下 ...

  9. Android四大组件之Activity(活动)及其布局的创建与加载布局

    Android四大组件之Activity(活动)及其布局的创建与加载布局 什么是Activity ? 活动(Activity)是包含用户界面的组件,主要用于和用户进行交互的,一个应用程序中可以包含零个 ...

随机推荐

  1. 使用自定义材质球,实现NGUI屏幕溶解和灰显

    UITexture实现的溶解: 重设UITeture的材质球实现上述效果,把当前屏幕渲染的Texture2D丢给UITexture,即可实现UI屏幕特效,背景模糊等都可以. 难点主要是实时刷新问题 解 ...

  2. COM技术の组件

    什么是COM COM,Component Object Mode即组件对象模型.之所以称之为“模型”,是表明COM是一种编程规范(非具体代码),通过这种规范我们能够编写出语言无关的,可扩展的,内部变化 ...

  3. [kipmi0]进程导致系统负载高

    最近一个用户这边服务器运行四五天就会出现服务器负载很高的情况,原本正常是0.3~0.5左右  不正常的时候会达到3,重启机器就正常,开始以为是程序问题,后来在观察的时候把程序给杀掉了 然后重启,结果负 ...

  4. Linux内核中的Kconfig、xx.defconfig、xx.config、Makefile

    什么是Kconfig.xx.defconfig.xx.config.Makefile Kconfig: 一个文本形式的文件,其中主要作用是在内核配置时候,作为配置选项. xx.deconfig: Li ...

  5. Tar命令用法详解

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  6. Eclipse如何生成jar包

    Eclipse如何生成jar包 图1 右击项目Properites,选择Android,选择Is Library,然后会编译生成jar包在bin目录下.

  7. C#其他

    1.switch - if ...else if...switch(表达式) { case 值: ..... break; case 值: ..... break; default: ..... br ...

  8. BZOJ 3199 escape

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3199 题意:给出n个点.对于平面上任意一点p,p到n个点中的哪个点的距离最近我们就 ...

  9. SQL判断汉字

    /* unicode编码范围: 汉字:[0x4e00,0x9fa5](或十进制[19968,40869]) 数字:[0x30,0x39](或十进制[48, 57]) 小写字母:[0x61,0x7a]( ...

  10. [HDOJ3714]Error Curves(三分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 题意:求n个二次函数在[0,1000]的最小值. 三分枚举. #include <bits ...