##常见的布局
* LinearLayout 线性布局
线性布局往左右拉是拉不动的,
> 线性布局的朝向 vertical|horizontal
> 线性布局的权重 weight 和 0dip一起使用

<?xml version="1.0" encoding="utf-8"?>
<!-- 线性布局控件自上而下整齐的排列 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > 垂直排列,里面的内容垂直排列 <Button
android:layout_width="match_parent"
android:layout_height="0dip" 高度为0,则高度根据权重来占比例,
android:layout_weight="1" 权重为1,则高度为权重和的1份即1/3,权重只能跟为0的宽度或高度,
android:text="按钮1" /> <Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="按钮2" /> <Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="按钮3" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- 线性布局控件自左向右整齐的排列 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" > 水平排列,不用权重则多的将会挤出去, <Button
android:layout_width="0dip" 宽度为0,
android:layout_height="wrap_content" 高度填充父窗体,和父组件宽度一样宽,
android:layout_weight="2" 权重为2,则宽度为权重和的2份即2/4,权重只能跟为0的宽度或高度,
android:text="按钮1" /> <Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" 权重为1,则宽度为权重和的1份
android:text="按钮2" /> <Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" 权重为1,则宽度为权重和的1份
android:text="按钮3" /> </LinearLayout>

以上的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > 最外层是线性布局,垂直排列 <LinearLayout
android:orientation="horizontal" 里面是水平排列
android:layout_width="match_parent" 宽度为父窗体宽度
android:layout_weight="1" 权重为1
android:layout_height="0dip" > 写0可以用权重了
<TextView
android:layout_width="0dip" 宽度为0
android:layout_height="fill_parent" 高度为父窗体
android:layout_weight="1" 宽度权重为1
android:background="#ff0000"
/>
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00ff00"
/>
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0000ff"
/> </LinearLayout> <LinearLayout
android:orientation="vertical" 里面垂直排列
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dip" >
<TextView
android:layout_width="fill_parent" 宽度为父窗体
android:layout_height="0dip" 高度为0
android:layout_weight="1" 高度权重为1
android:background="#ff0000"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#00ff00"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#0000ff"
/> </LinearLayout> </LinearLayout>

android 59 LinearLayout 线性布局的更多相关文章

  1. Android之LinearLayout线性布局

    1.相关术语解释 orientation 子控件的排列方式,horizontal(水平)和vertical(垂直默认)两种方式! gravity 子控件的对齐方式,多个组合 layout_gravit ...

  2. Android 自学之线性布局 LinearLayout

    线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来. 他们最大的区别在于:Android的线性布局不会换行:AWT里面的F ...

  3. Android布局管理详解(1)—— LinearLayout 线性布局

    Android的布局方式共有6种,分别是LinearLayout(线性布局).TableLayout(表格布局).FrameLayout(帧布局).RelativeLayout(相对布局).GridL ...

  4. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  5. Android零基础入门第25节:最简单最常用的LinearLayout线性布局

    原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...

  6. 2.2.1 LinearLayout(线性布局)

    本节引言 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局), RelativeLayout(相对布局), TableLayout(表格布局) ...

  7. Android LinearLayout线性布局

    LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...

  8. .Net程序猿玩转Android开发---(6)线性布局LinearLayout

                                LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...

  9. Android开发之线性布局详解(布局权重)

    布局权重 线性布局支持给个别的子视图设定权重,通过android:layout_weight属性.就一个视图在屏幕上占多大的空间而言,这个属性给其设 定了一个重要的值.一个大的权重值,允许它扩大到填充 ...

随机推荐

  1. XCode 项目配置说明

    初学XCode最让人头疼的就是项目各属性设置,各种不解,这里做个总结: 项目配置: 基本项(Basic) 1.Architectures(指令集)——设置你想支持的指令集,目前ios的指令集有以下几种 ...

  2. js写分页

    jsp:< input value ="1" id ="current" type ="hidden"/> <div id ...

  3. 基于opencv的小波变换

    基于opencv的小波变换 提供函数DWT()和IDWT(),前者完成任意层次的小波变换,后者完成任意层次的小波逆变换.输入图像要求必须是单通道浮点图像,对图像大小也有要求(1层变换:w,h必须是2的 ...

  4. ACM俱乐部算法基础练习赛(1)

    A: 水题 代码: #include<cstdio> #include<algorithm> using namespace std; ]; int n,m,c; int ma ...

  5. 形形色色Node工程Angular2

    最近项目要用的 一些无关紧要的文件夹, demo是一些示例, dist是webpack打包后发布的代码,server是用node启动服务,typings和tsconfig是一些ts配置. npm in ...

  6. 【BZOJ 3926】 [Zjoi2015]诸神眷顾的幻想乡 (广义SAM)

    3926: [Zjoi2015]诸神眷顾的幻想乡 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 974  Solved: 573 Descriptio ...

  7. iOS开发UI篇—UITableviewcell的性能问题

    iOS开发UI篇—UITableviewcell的性能问题 一.UITableviewcell的一些介绍 UITableView的每一行都是一个UITableViewCell,通过dataSource ...

  8. 【CF】259 Div.1 B Little Pony and Harmony Chest

    还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...

  9. win8.1右键没有“新建”选项

    # 记事本中新建以下代码,复制粘贴进去,# 将.txt格式改为.reg,双击运行它就行了. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROO ...

  10. Python 处理server返回gzip内容

    Python 如何处理server返回gzip压缩过的内容,代码如下: from StringIO import StringIOimport gzip request = urllib2.Reque ...