一、布局概述:

  布局为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. jqeury之平移轮播

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. U3D UGUI学习4 - Text

    1.对应NGUI的四种文字显示模式 Shrink Content 对应NGUI第一种模式     勾选Best Fit 但似乎有一个Bug,文字过多的时候会爆框.解决方法是改变Line Spacing ...

  3. linux内核2.4.x网络接口分析层次图

    http://blog.csdn.net/wswifth/article/details/5108744 今天大概分写了下<Linux内核2.4.x的网络接口源码的结构[转]>中的结构层次 ...

  4. 谷歌Chrome浏览器如何设置网页的默认编码方法

    设置->高级->自定义字体->编码->utf-8

  5. tinyhttpd服务器源码学习

    下载地址:http://sourceforge.net/projects/tinyhttpd/ /* J. David's webserver */ /* This is a simple webse ...

  6. Entity Framework 第七篇 简化排序

    上篇介绍了EF的分页实现,分页的时候会用到排序,但是使用起来表达式写的似乎很繁琐 , ); 如果直接使用排序字符串,不更直观简便么? respository.GetPaged<S_Users&g ...

  7. 基于APK的Robotium登录人人网与发状态

    搭建好Robotium的环境,大致就是下载安装jdk并配置环境变量,下载并打开Eclipse,下载安装Android SDK Tools并配置环境变量,下载安装ADT插件,创建并打开Android V ...

  8. hibernate的like用法(用占位符解决)

    原本我的写法:Query repeatClientQuery=querysession.createQuery("from ClientInfo as a " +"whe ...

  9. fragment (1)简单示例:定义,界面配置,fragment之间的跳转

    fragment作用 同一程序中切换界面 比activity轻快,灵活. fragment代码示例 ide  : android studio 1.2 sdk : 22 package com.exa ...

  10. Java中HashMap遍历的两种方式

    Java中HashMap遍历的两种方式 转]Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml 第一种: ...