Android——学习:线性布局权重分配
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——学习:线性布局权重分配的更多相关文章
- Android学习----五大布局
1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...
- Android LinearLayout线性布局
LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...
- android 学习Layout布局的使用
android 常用布局 LinearLayout(线性布局) 线性的 垂直的 水平的RelativeLaytout(相对布局) 最灵活的TableLayout(表格布局) 使用GridView代替A ...
- android 学习 之 布局(上)
学习安卓布局前,先了解三个属性值: 1.fill_parent: 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间 2.match_parent: And ...
- Android LinearLayout线性布局详解
为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器.通过使用布局管理器,Android应用图形用户界面具有良好的平台无关性.推荐使用布局管理器来管理组件的分布.大小, ...
- Android学习5—布局简介
Android界面的布局主要有四种,分别为RelativeLayout.LinearLayout.TableLayout.FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的 ...
- Android学习——LinearLayout布局实现居中、左对齐、右对齐
android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...
- Android 使用线性布局LinearLayout和Button实现一个点红块游戏
这个游戏的功能类似打地鼠. 项目地址:https://github.com/moonlightpoet/RedBlock 程序下载试玩地址:https://github.com/moonlightpo ...
- android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
随机推荐
- 视频处理控件TVideoGrabber如何重新编码视频/音频(2)
在前面的文中<视频处理控件TVideoGrabber如何重新编码视频>已经讲解了部分TVideoGrabber重新编码音频.视频剪辑的内容,下面将继续说明. 重新编码进程 重新编码开始时, ...
- mybatis 复习笔记03
参考:http://www.mybatis.org/mybatis-3/zh/configuration.html 入门 1. 从 XML 中构建 SqlSessionFactory 每个基于 MyB ...
- 从追MM谈Java的23种设计模式(转)
从追MM谈Java的23种设计模式 这个是从某个文章转载过来的.但是忘了原文链接.如果知道的,我追加一下. 1.FACTORY-追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西 ...
- 【转载】Perl异常处理方法总结
程序脚本在运行过程中,总会碰到这样那样的问题,我们会预知一些问题并为其准备好处理代码,而有一些不能预知.好的程序要能尽可能多的处理可能出现的异常问题,本文就总结了一些方法来解决这些异常,当然perl在 ...
- javascript || and &&
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Shell之while循环
While循环的格式: while expression do command command ... done 1.计数器控制的while循环:主要用于已经准确知道要输入的数据和字符串的数目. 例子 ...
- bootstrap/moban191/js/templatemo_custom.js
(function($) { "use strict"; // Cache selectors var lastId, topMenu = $(".menu-holder ...
- SQL基础教程
第一范式: 列仅包含原子值: 没有重复的组. 第二范式: 满足第一范式: 非部分函数依赖.(如果组合键中任何一列值改变,将导致非键列的值需要被更新) 那么,主键是一列(不是组合的)满足第二范式:所有列 ...
- Redis群集实现Asp.net Mvc分布式Session
Session的缺点 众所周知Asp.net Session默认存储在IIS中,IIS的重启会导致Session丢失. 如果你的网站使用了session,当网站并发过大时可能引起溢出. 配置Redis ...
- Android动画的使用总结
1.补间动画(透明渐变.平移.旋转.缩放.组合) 方法一:通过xml文件设置 1-1:创建:res/anim 1-2:java代码写调用 Animation a = AnimationUtils.lo ...