一:LinearLayout

     1、线性布局,这个东西,从外框上可以理解为一个div,他首先是一个一个从上往下罗列在屏幕上。每一个LinearLayout里面又可分为垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )。当垂直布局时,每一行就只有一个元素,多个元素依次垂直往下;水平布局时,只有一行,每一个元素依次向右排列。
  linearLayout中有一个重要的属性 android:layout_weight="1",这个weight在垂直布局时,代表行距;水平的时候代表列宽;weight值越大就越大。

    2、TextView占一定的空间,没有赋值也有一定的宽高,要特别注意。

    第一个实例

    效果图:

     

    代码: 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
>
<!-- android:gravity="right"表示Button组件向右对齐 -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="确定"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="取消"
/>
</LinearLayout>
</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"
> <TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#3C3C3C" /> <TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFEFD5"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="#66CDAA"
android:orientation="horizontal"
> <TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="1"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#E82917"
android:layout_weight="4" />
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>

    我们要做的就是多多实践,多看下关于软件的布局。软件上的布局和真机上的布局有差异,我们尽可能的拿真机去测验,并且在不同的机型上去测验。

 

Android开发--布局的更多相关文章

  1. Android开发——布局性能优化的一些技巧(一)

    0. 前言 上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布 ...

  2. android开发--布局三(微信布局)

    微信主界面 我们布局应该从局来看,如上图,我们可以分为三个大的LinearLayout,再从LinearLayout嵌套其它布局,从而做出界面 文件 主界面代码: <LinearLayout x ...

  3. Android开发--布局二

    1.Andrid:控件布局(表格布局)TableLayout 有多少个TableRow对象就有多少行, 列数等于最多子控件的TableRow的列数 直接在TableLayout加控件,控件会占据一行 ...

  4. 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight

    线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...

  5. android开发布局优化之ViewStub

    使用ViewStub可以延迟加载一个布局文件,提高显示速率.刚开始接触到,记录下来. 关于viewstub的使用,我们可以在不同的布局中使用,比如可以根据设备的大小动态决定显示哪个界面. viewst ...

  6. Android开发布局 案例一

    权重:就是在布局界面中所占的比例 实践案例: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  7. android开发布局文件imageview 图片等比例缩放:

    ImageView的属性scaleType,如果等比缩放的话,就使用CenterInside,如果想固定大小的话,就CenterCrop <?xml version="1.0" ...

  8. Android开发——布局性能优化的一些技巧(二)

    , 0, drawable.getMinimumWidth(),dra.getMinimumHeight()); tv.setCompoundDrawables(null, null, drawabl ...

  9. Android开发布局 案例二

    实践案例: XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

随机推荐

  1. easyUI笔记09.03

    layout的布局可以自适应 <body class="easyui-layout"> <div data-options="region:'north ...

  2. sqlserver08评估期已过的解决方法

    打开sqlserver出现提示:评估期已过.有关如何升级的测试版软件的信息,请访问http://www.microsoft.com/sql/howtobuy 解决方法如下: 第一步:进入开始菜单--- ...

  3. poj 3463 最短路与次短路的方案数求解

    Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8968   Accepted: 3139 Descr ...

  4. 037. asp.netWeb用户控件之五使用用户控件实现文件上传功能

    fileUpload.ascx代码: <%@ Control Language="C#" AutoEventWireup="true" CodeFile= ...

  5. SSH 创建证书认证

    *******chmod 600 195-tempuser.txt******* useradd tempusersu tempusercdmkdir .sshchmod 700 .sshcd .ss ...

  6. mui适用场景说明,能不能在普通浏览器里使用,能否用于wap网站

    mui适用场景说明 为解决HTML5在低端Android机上的性能缺陷,mui引入了原生加速,其中最关键的就是webview控件,因此mui若要发挥其全部能力,需和5+ App配合适用,若脱离5+ A ...

  7. loose coupling之函数签名

    当函数的参数有多个时(比如多于4个),可以考虑将这些参数组织放入一个class(struct),然后函数参数就减少为一个. 1.以class instance来穿参数,可以很容易在各个函数之间传递参数 ...

  8. 生成freemarker静态页面的工具类

    package cn.bocai.pc.util; import java.io.BufferedWriter;import java.io.File;import java.io.FileOutpu ...

  9. mysql的ONLY_FULL_GROUP_BY语义 --转自http://www.wtoutiao.com/p/19dh3ec.html

    执行SET GLOBAL sql_mode = ''; 把sql_mode 改成非only_full_group_by模式.验证是否生效 SELECT @@GLOBAL.sql_mode 或 SELE ...

  10. sqlserver2008 ,只能选C盘目录,不能选其它盘目录

    数据库sql2008安装后,无论备份或还原,只能看到C盘,手工输入路径,错误提示如下:尝试打开或创建物理文件 'D:\数据库\db.mdf' 时,CREATE FILE 遇到操作系统错误 5(拒绝访问 ...