LinearLayout在Android中被广泛使用,LinearLayout有一个比较重要的属性——android:layout_weight。按照字面理解就是该控件的权重,这个值默认是 零(0)。

  举个例子:

  在下图中,整个界面是一个Linearlayout,包含了5个子控件Linerarlayout,分别是空的、用户名的、密码的、确认和取消按钮的、保存用户的layout。

  在这里,先给整个界面设置20个权重,再给子控件layout分别设置:10、1、2、3、1个权重,最后的效果就是上图。


  Xml文件代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mailLayout"
android:orientation="vertical"
android:background="@drawable/login_background"
android:weightSum="20"
>
<!-- 空白部分 -->
<LinearLayout
android:id="@+id/loginSpace"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
> </LinearLayout>
<!-- 登陆用户名 -->
<LinearLayout
android:id="@+id/loginNameLayout"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/loginTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_text_name"
/>
<EditText
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:layout_marginLeft="10dip"
android:background="@drawable/login_name_input"
/>
</LinearLayout>
<!-- 登陆密码 -->
<LinearLayout
android:id="@+id/loginPasswordLayout"
android:layout_weight="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/loginTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_text_pwd"
/>
<EditText
android:id="@+id/passWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:password="true"
android:layout_marginLeft="11dip"
android:background="@drawable/login_pwd_input"
/>
</LinearLayout> <!-- 确认登陆按钮和取消按钮 -->
<LinearLayout
android:id="@+id/loginButtonLayout"
android:layout_weight="3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
> <ImageButton
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_confirm_button"
android:background="@null"
/>
<ImageButton
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dip"
android:src="@drawable/login_text_cancel"
android:background="@null" />
</LinearLayout> <!-- 保存用户名和密码 -->
<LinearLayout
android:id="@+id/loginSaveUserLayout"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
>
<CheckBox
android:id="@+id/saveUserInfoCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/login_checkbox"
android:checked="true" />
<TextView
android:id="@+id/loginTextSaveUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/login_saveuser" />
</LinearLayout>
</LinearLayout>

Android——学习:线性布局权重分配的更多相关文章

  1. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

  2. Android LinearLayout线性布局

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

  3. android 学习Layout布局的使用

    android 常用布局 LinearLayout(线性布局) 线性的 垂直的 水平的RelativeLaytout(相对布局) 最灵活的TableLayout(表格布局) 使用GridView代替A ...

  4. android 学习 之 布局(上)

    学习安卓布局前,先了解三个属性值: 1.fill_parent: 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间 2.match_parent: And ...

  5. Android LinearLayout线性布局详解

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

  6. Android学习5—布局简介

    Android界面的布局主要有四种,分别为RelativeLayout.LinearLayout.TableLayout.FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的 ...

  7. Android学习——LinearLayout布局实现居中、左对齐、右对齐

    android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...

  8. Android 使用线性布局LinearLayout和Button实现一个点红块游戏

    这个游戏的功能类似打地鼠. 项目地址:https://github.com/moonlightpoet/RedBlock 程序下载试玩地址:https://github.com/moonlightpo ...

  9. android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

随机推荐

  1. 我是如何对网站CSS进行架构的

    by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=944 一.写在前面的 ...

  2. V4L2应用程序框架--一【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11369667 V4L2是V4L的升级版本,linux下视频设备程序提供了一套接口规范. ...

  3. 精通 JS正则表达式

    一.正则表达式可以: 测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 替换文本.可以在文档中使用一个正则表达式 ...

  4. Linux workqueue疑问【转】

    转自:http://blog.csdn.net/angle_birds/article/details/9387365 各位大神,你们好.我在使用workqueue的过程中遇到一个问题. 项目采用uC ...

  5. ServiceStack.Redis常用操作 - 事务、并发锁_转

    一.事务 使用IRedisClient执行事务示例: using (IRedisClient RClient = prcm.GetClient()) { RClient.Add("key&q ...

  6. page指令

    <%@ page 属性1=“value” 属性2=“value2” ......%> page的属性有13种: 1)language  --- 声明所使用的脚本语言的种类.(可省略) va ...

  7. grep、egrep、fgrep

    grep: global search regular expression and printing

  8. 在centos6.5-64bit上安装wxHexEditor,以查看编译二进制文件

    目前在做一个存储,磁盘里面的数据老是出现很诡异的地方,某个通道的录像播放到一半的时候,切换到另外一个通道的视频上去了,一直不知道怎么下手,想着用十六进制编辑器查看磁盘数据. sudo yum inst ...

  9. PHP中header函数的用法及其注意重点是什么呢

    1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...

  10. 织梦系统中出现DedeTag Engine Create File False提示原因及解决方法

    今天更新网站时dedecms系统时,遇到一个问题:DedeTag Engine Create File False  出现这样的提示. 其实这也不算是什么错误,我个人觉得最重要的一点就是根目录下没有给 ...