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. unix

    BSD (Berkeley Software Distribution,伯克利软件套件)是Unix的衍生系统,在1977至1995年间由加州大学伯克利分校开发和发布的.历史上, BSD曾经被认为是UN ...

  2. input放在a标签里面不能选择input里面的文本,IE9点击失效

    input放在a标签里面不能选择input里面的文本,IE9点击失效 在IE浏览器中<input type="text" value="test" /&g ...

  3. TI CC2541的LED控制

    现在终于进入到蓝牙SPI的环节了, 下面还要研究I2C, 所以第一步, 先点灯, 就是GPIO控制吧. 参考一下LEd的初始化: void HalLedInit (void){#if (HAL_LED ...

  4. windows cmd command line 命令

    Reference: 1. http://msdn.microsoft.com/en-us/library/ms977170.aspx(前面有一段VB看不懂没关系) 2. http://csserve ...

  5. Zabbix中使用ICMP ping来判断主机是否存活的问题

    上一节配置了Simple check,现在来通过Simple check 用ICMP ping来监控充节点运行情况.Zabbix使用fping处理ICMP ping的请求,需要安装fping程序,安装 ...

  6. minio-dotnet --云存储服务

    inio是一家成立于2014年的生产开源云存储产品的新兴创业公司.这家创业公司是其创始人继Gluester之后的又一杰作,Gluester公司已经在2011年被Red Hat公司以1.36亿美元的价格 ...

  7. ExtJS的MessageBox总结

    自己写了个ExtJS的MsgBox的小模版,以后遇到需要使用提示的地方就拿过来改改,免得每次都重新写. /**MsgBox start**/ Ext.Msg.buttonText.yes = &quo ...

  8. Centos7 安装配置NFS

    一.安装 NFS 服务器所需的软件包 # yum install -y nfs-utils 二.编辑exports文件 # vim /etc/exports /data/disk1/video *(a ...

  9. 将helps.php或者functions.php直接进行了加载

    TP3系列中functions.php文件默认其实是空文件,很好找.我们可以直接封装代码. Laravel5系列中的path/vendor/laravel/framework/src/Illumina ...

  10. 使用Symfony 2在三小时内开发一个寻人平台

    简介 Symfony2是一个基于PHP语言的Web开发框架,有着开发速度快.性能高等特点.但Symfony2的学习曲线也比 较陡峭,没有经验的初学者往往需要一些练习才能掌握其特性. 本文通过一个快速开 ...