分类:C#、Android、VS2015;

创建日期:2016-02-10

一、简介

LinearLayout将容器内的组件一个挨着一个地横向或纵向依次堆叠起来(不重叠)。该布局和WPF的StackPanel控件的功能非常相似,也是通过orientation属性设置排列的方向是纵向(vertical)还是纵向(horizontal)。

常用属性有:

android:layout_gravity:子元素在容器中的对齐方式。即:往哪一端偏沉(gravity:重力)。

android:orientation:控制子元素的排列方式(横向排列、纵向排列)

android:layout_weight:表示其子元素占用空间的分配权重,值越小权重越大。

例如:

<LinearLayout

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

注意:子元素的宽和高必须至少有一个设置为“fill_parent”线性布局才会起作用。

二、示例—Demo01LinearLayout

1、设计界面

2、运行效果

3、添加Demo01LinearLayout.axml文件

在layout文件夹下添加该文件。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <LinearLayout
  7. android:orientation="horizontal"
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent"
  10. android:layout_weight="1">
  11. <TextView
  12. android:text="red"
  13. android:gravity="center_horizontal"
  14. android:background="#aa0000"
  15. android:layout_width="wrap_content"
  16. android:layout_height="fill_parent"
  17. android:layout_weight="1" />
  18. <TextView
  19. android:text="green"
  20. android:gravity="center_horizontal"
  21. android:background="#00aa00"
  22. android:layout_width="wrap_content"
  23. android:layout_height="fill_parent"
  24. android:layout_weight="1" />
  25. <TextView
  26. android:text="blue"
  27. android:gravity="center_horizontal"
  28. android:background="#0000aa"
  29. android:layout_width="wrap_content"
  30. android:layout_height="fill_parent"
  31. android:layout_weight="1" />
  32. <TextView
  33. android:text="yellow"
  34. android:gravity="center_horizontal"
  35. android:background="#aaaa00"
  36. android:layout_width="wrap_content"
  37. android:layout_height="fill_parent"
  38. android:layout_weight="1" />
  39. </LinearLayout>
  40. <LinearLayout
  41. android:orientation="vertical"
  42. android:layout_width="fill_parent"
  43. android:layout_height="fill_parent"
  44. android:layout_weight="1">
  45. <TextView
  46. android:text="第1行"
  47. android:textSize="15pt"
  48. android:layout_width="fill_parent"
  49. android:layout_height="wrap_content"
  50. android:layout_weight="1" />
  51. <TextView
  52. android:text="第2行"
  53. android:textSize="15pt"
  54. android:layout_width="fill_parent"
  55. android:layout_height="wrap_content"
  56. android:layout_weight="1" />
  57. <TextView
  58. android:text="第3行"
  59. android:textSize="15pt"
  60. android:layout_width="fill_parent"
  61. android:layout_height="wrap_content"
  62. android:layout_weight="1" />
  63. <TextView
  64. android:text="第4行"
  65. android:textSize="15pt"
  66. android:layout_width="fill_parent"
  67. android:layout_height="wrap_content"
  68. android:layout_weight="1" />
  69. </LinearLayout>
  70. </LinearLayout>

4、添加Demo01LinearLayout.cs文件

在SrcDemos文件夹下添加该文件。

  1. using Android.App;
  2. using Android.OS;
  3. namespace ch07demos.SrcDemos
  4. {
  5. [Activity(Label = "Demo01LinearLayout")]
  6. public class Demo01LinearLayout : Activity
  7. {
  8. protected override void OnCreate(Bundle savedInstanceState)
  9. {
  10. base.OnCreate(savedInstanceState);
  11. SetContentView(Resource.Layout.Demo01LinearLayout);
  12. }
  13. }
  14. }

运行观察效果。

【Android】7.2 LinearLayout(线性布局)的更多相关文章

  1. android 59 LinearLayout 线性布局

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

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

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

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

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

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

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

  5. 2.2.1 LinearLayout(线性布局)

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

  6. Android学习笔记(11):线性布局LinearLayout

    线性布局LinearLayout是指在横向或是竖向一个接一个地排列.当排列的组件超出屏幕后,超出的组件将不会再显示出来. LinearLayout支持的XML属性和相应方法如表所看到的: Attrib ...

  7. Android LinearLayout线性布局

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

  8. Android LinearLayout线性布局详解

    为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器.通过使用布局管理器,Android应用图形用户界面具有良好的平台无关性.推荐使用布局管理器来管理组件的分布.大小, ...

  9. android的布局-----LinearLayout(线性布局)

    学习导图(图片在网上下载) 知识点详解(演示效果方便组件没有设置id) (1)gravity和Layout_gravity android:gravity 属性是对该view中内容的限定.比如一个bu ...

  10. Android基础_2 Activity线性布局和表格布局

    在activity的布局中,线性布局和表格布局是最简单的,这次分别从线性布局,表格布局以及线性布局和表格混合布局做了实验,实验中只需要编写 相应的xml的代码,java代码不需要更改,因为我们这里只是 ...

随机推荐

  1. MySQL的各种SHOW

    . SHOW语法 13.5.4.1. SHOW CHARACTER SET语法 13.5.4.2. SHOW COLLATION语法 13.5.4.3. SHOW COLUMNS语法 13.5.4.4 ...

  2. JAVA Drp项目实战—— Unable to compile class for JSP 一波三折

    交代下背景.电脑系统是64位的,用的是64位的Tomcat.安装是32位的Myeclipse10,java环境也是32位的.Tomcat在開始启动时会报这样一个错误,"Can't load ...

  3. JUC-闭锁:CountDownLatch

    CountDownLatch::闭锁,在完成某些运算是,只有其他所有线程的运算全部完成,当前运算才继续执行. 实例化:参数:设置一个计数器的值. final CountDownLatch latch ...

  4. lr如何获取当前系统时间戳

    lr如何获取当前系统时间戳 一般使用time函数,获取当前unix时间戳 lr程序如下: int t1; char a[20]; t1=time();//获取当前系统时间 //根据不同情况,将时间存储 ...

  5. 九度OJ 1183 守形数 (模拟)

    题目1183:守形数 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2663 解决:1424 题目描写叙述: 守形数是这样一种整数.它的平方的低位部分等于它本身. 比方25的平方是625. ...

  6. 转载【微信小程序】:微信小程序滚动Tab选项卡:左右可滑动切换(仿某宝)

    1.本文转载至:http://blog.csdn.net/sophie_u/article/details/71745125 2.效果: 3.最终效果如上.问题: 1).tab标题总共8个,所以一屏无 ...

  7. HDUOJ -----1864 最大报销额(动态规划)

    最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDUOJ ----1709

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. mermaid 语法

    a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2p ...

  10. DBA_实践指南系列7_Oracle Erp R12监控OAM(案例)

    2013-12-07 Created By BaoXinjian