1. import android.os.Bundle;
  2. import android.app.Activity;
  3.  
  4. public class Layout03 extends Activity {
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.main);
  10. }
  11. }
  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="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <LinearLayout
  8. android:orientation="horizontal"
  9. android:layout_width="fill_parent"
  10. android:layout_height="fill_parent"
  11. android:layout_weight="3">
  12. <TextView
  13. android:text="red"
  14. android:gravity="center_horizontal"
  15. android:background="#aa0000"
  16. android:layout_width="wrap_content"
  17. android:layout_height="fill_parent"
  18. android:layout_weight="1"/>
  19. <TextView
  20. android:text="green"
  21. android:gravity="center_horizontal"
  22. android:background="#00aa00"
  23. android:layout_width="wrap_content"
  24. android:layout_height="fill_parent"
  25. android:layout_weight="1"/>
  26. <TextView
  27. android:text="blue"
  28. android:gravity="center_horizontal"
  29. android:background="#0000aa"
  30. android:layout_width="wrap_content"
  31. android:layout_height="fill_parent"
  32. android:layout_weight="2"/>
  33. <TextView
  34. android:text="yellow"
  35. android:gravity="center_horizontal"
  36. android:background="#aaaa00"
  37. android:layout_width="wrap_content"
  38. android:layout_height="fill_parent"
  39. android:layout_weight="1"/>
  40. </LinearLayout>
  41.  
  42. <LinearLayout
  43. android:orientation="vertical"
  44. android:layout_width="fill_parent"
  45. android:layout_height="fill_parent"
  46. android:layout_weight="1">
  47. <TextView
  48. android:text="row one"
  49. android:textSize="15pt"
  50. android:layout_width="fill_parent"
  51. android:layout_height="wrap_content"
  52. android:layout_weight="1"/>
  53. <TextView
  54. android:text="row two"
  55. android:textSize="15pt"
  56. android:layout_width="fill_parent"
  57. android:layout_height="wrap_content"
  58. android:layout_weight="1"/>
  59. <TextView
  60. android:text="row three"
  61. android:textSize="15pt"
  62. android:layout_width="fill_parent"
  63. android:layout_height="wrap_content"
  64. android:layout_weight="1"/>
  65. <TextView
  66. android:text="row four"
  67. android:textSize="15pt"
  68. android:layout_width="fill_parent"
  69. android:layout_height="wrap_content"
  70. android:layout_weight="1"/>
  71. </LinearLayout>
  72. </LinearLayout>
  73. <!--
  74. layout_weight属性:它的值是整型,用于指定空闲空间的分配比例
  75. -->

实现该布局:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. android:paddingBottom="@dimen/activity_vertical_margin"
  7. android:paddingLeft="@dimen/activity_horizontal_margin"
  8. android:paddingRight="@dimen/activity_horizontal_margin"
  9. android:paddingTop="@dimen/activity_vertical_margin"
  10. tools:context=".MainActivity" >
  11.  
  12. <!--第一步是一个textView -->
  13. <TextView
  14. android:layout_width="match_parent"
  15. android:layout_height="wrap_content"
  16. android:gravity="center"
  17. android:text="@string/huang" />
  18.  
  19. <LinearLayout
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:orientation="horizontal" >
  23.  
  24. <LinearLayout
  25. android:layout_width="0dp"
  26. android:layout_height="match_parent"
  27. android:orientation="vertical"
  28. android:layout_weight="1"
  29. >
  30.  
  31. <ImageView
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:src="@drawable/feng"
  35. />
  36.  
  37. <RadioGroup
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"
  40. >
  41. <RadioButton
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:text="石头"
  45. />
  46. <RadioButton
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:text="剪刀"
  50. />
  51. <RadioButton
  52. android:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:text="布"
  55. />
  56.  
  57. </RadioGroup>
  58.  
  59. </LinearLayout>
  60.  
  61. <LinearLayout
  62. android:layout_width="0dp"
  63. android:layout_height="match_parent"
  64. android:orientation="vertical"
  65. android:layout_weight="1"
  66. >
  67.  
  68. <ImageView
  69. android:layout_width="wrap_content"
  70. android:layout_height="wrap_content"
  71. android:src="@drawable/jian"
  72. />
  73.  
  74. <RadioGroup
  75. android:layout_width="wrap_content"
  76. android:layout_height="wrap_content"
  77. >
  78. <RadioButton
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"
  81. android:text="石头"
  82. />
  83. <RadioButton
  84. android:layout_width="wrap_content"
  85. android:layout_height="wrap_content"
  86. android:text="剪刀"
  87. />
  88. <RadioButton
  89. android:layout_width="wrap_content"
  90. android:layout_height="wrap_content"
  91. android:text="布"
  92. />
  93.  
  94. </RadioGroup>
  95.  
  96. </LinearLayout>
  97. </LinearLayout>
  98.  
  99. <!--第二步是一个Button -->
  100. <Button
  101. android:layout_width="match_parent"
  102. android:layout_height="wrap_content"
  103. android:gravity="center"
  104. android:text="@string/action"
  105. />
  106.  
  107. <!--第三步是一个LinearLayout,里面有两个TextView -->
  108. <LinearLayout
  109. android:orientation="horizontal"
  110. android:layout_width="match_parent"
  111. android:layout_height="match_parent"
  112. >
  113.  
  114. <TextView
  115. android:layout_width="0dp"
  116. android:layout_height="wrap_content"
  117. android:text="结果"
  118. android:layout_weight="1"
  119. />
  120.  
  121. <TextView
  122. android:layout_width="0dp"
  123. android:layout_height="wrap_content"
  124. android:text="测试结果"
  125. android:layout_weight="1"
  126. />
  127. </LinearLayout>
  128.  
  129. </LinearLayout>

如果应用程序布局嵌套的越多性能就会降低

控件布局_LinearLayout的嵌套的更多相关文章

  1. 控件布局_LinearLayout

    gravity和layout_gravity的区别 android:gravity与android:layout_gravity.他们的区别在于:android:gravity用于设置View组件的对 ...

  2. CSharpGL(26)在opengl中实现控件布局/渲染文字

    CSharpGL(26)在opengl中实现控件布局/渲染文字 效果图 如图所示,可以将文字.坐标轴固定在窗口的一角. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入( ...

  3. React-Native 之控件布局

    Nodejs 一度将前端JS 推到了服务器端,而15年FB的React-Native RN再一次将JS 推到了移动端的开发浪潮中.RN的优势这里不再重复,它是我们这些习惯了服务端.web端开发,而又不 ...

  4. 运用 BoxLayout 进行 Swing 控件布局

    摘自http://www.cnblogs.com/fnlingnzb-learner/p/6008572.html 运用 BoxLayout 进行 Swing 控件布局 对于初学 Java Swing ...

  5. 学习笔记<4>初步控件布局

    一.控件布局基本概念 指控制控件在Activity当中的位置.大小.颜色以及其他控件样式属性 二.控件布局两种方法 1.使用布局文件完成控件布局(eclipse可视化拖拽控件实现) 2.在JAVA代码 ...

  6. 利用wtl的CDialogResize自动调整atl ActiveX控件布局

    前言 利用atl 开发activex控件时,如果使用atl复合控件时,acitvex控件上的界面元素不会自动改变大小,如果自己在OnSize中处理每个子控件的布局是一件非常麻烦的事,我们可以借助wtl ...

  7. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  8. CPF 入门教程 - 控件布局(六)

    CPF netcore跨平台桌面UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) CPF 入门教程 - 样式和动画(三) CPF 入门教程 - 绘图(四) C ...

  9. Android:控件布局(线性布局)LinearLayout

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

随机推荐

  1. POJ 1724 ROADS(使用邻接表和优先队列的BFS求解最短路问题)

    题目链接: https://cn.vjudge.net/problem/POJ-1724 N cities named with numbers 1 ... N are connected with ...

  2. Session会话保持机制的原理与Tomcat Session共享的几种实现方式(Session Cluster、memcached+MSM)

    一.Session的定义 在计算机科学中,特别是在网络中,session是两个或更多个通信设备之间或计算机和用户之间的临时和交互式信息交换.session在某个时间点建立,然后在之后的某一时间点拆除. ...

  3. Mybatis之逆向工程

    前面几篇基本把mybatis简单使用学习了下,今天学习下mybatis逆向工程,我们在开发中经常需要先设计数据库表结构或者先设计model,那就是能不能有工具可以只需在一边设计之后另一边自动生成呢?于 ...

  4. 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。

    错误提示:可能会导致循环或多重级联路径.请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束. 原因:自表连接(同一张表 ...

  5. [PHP] 算法-找出两个链表的第一个公共结点的PHP实现

    输入两个链表,找出它们的第一个公共结点 1.两个单链表,有公共结点,那么必然,尾部公用 2.找出链表1的长度,找出链表2的长度,长的链表减去短的链表得出一个n值 3.长的链表先走n步,两个链表再同时移 ...

  6. spark基本概念及入门

    spark spark背景 什么是spark Spark是一种快速.通用.可扩展的大数据分析引擎,2009年诞生于加州大学伯克利分校AMPLab,2010年开源,2013年6月成为Apache孵化项目 ...

  7. 浏览器与Tomcat交互

    浏览器与Tomcat交互 Web开发者都知道在Tomcat下部署应用后启动Tomcat即可通过浏览器与Tomcat建立连接. 那么二者之间的连接建立过程是怎么样的呢?(在此,我们不具体讲述关于网络底层 ...

  8. Java集合框架——容器的快速报错机制 fail-fast 是什么?

    前言:最近看 java 集合方面的源码,了解到集合使用了 fail-fast 的机制,这里就记录一下这个机制是什么,有什么用,如何实现的. 一.fail-fast 简介 fail-fast 机制,即快 ...

  9. Python中应用虚拟环境

    安装pip sudo apt-get install python3-dev sudo apt install python3-pip 安装virtualenv工具 sudo apt-get inst ...

  10. Python进阶点

    1. 模块化设计,分而治之 2. 组合数据类型 2.1 集合类型:list.set(无序/不重复),用于数据去重 2.2 序列类型:字符串.元组.列表(有序) 2.3 字典类型:根据字典中 k/v 来 ...