当前位置: 首页 > news >正文

Android 线性布局(LinearLayout)相关官方文档 - 指南部分

Android 线性布局(LinearLayout)相关官方文档 - 指南部分

太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的漂亮人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino否则。出自本博客的文章拒绝转载或再转载。谢谢合作。



Android 官方文档线性布局相关资源链接汇总例如以下:

android-sdk-macosx-4.4.2/docs/guide/topics/ui/layout/linear.html

android-sdk-macosx-4.4.2/docs/reference/android/widget/LinearLayout.html

android-sdk-macosx-4.4.2/docs/reference/android/widget/LinearLayout.LayoutParams.html



因为在线文档訪问困难,这里给出的是本地文档的相对路径。



重点摘要:

1、未指定权重的子视图,其是否占空间,所占空间具体由什么来决定。是按内容,还是按设定的宽、高值,或者由子视图重载 android.view.View 的 onMeasure 方法?

    a、理论分析结果:由原文句子 “The other two will expand equally to fill the space remaining after all three fields are measured. ”,能够初步判断是按 onMeasure 測定的宽、高来确定所占空间。而针对于大多数组件。会重载该方法来确定其内容所占空间,也即这一组件的宽、高设定为 "wrap_content" 所占空间。

    b、实际測试结果待补充。

2、为何正文中提示,宽、高属性要设置为 "0dp" ?假设没设置为  "0dp" 。其值是否会对子视图本身所占的无权重空间有影响?假设按权重分配的空间没有设定的宽或高值大。会如何?假设宽或高设置为  "0dp" ,此时权重分配的空间仍没有其本身内容占用空间大。会如何?

    a、理论分析结果:没思路。不知道会是啥结果;

    b、实际測试结果待补充。


译文来源:guide/topics/ui/layout/linear.html

线性布局 Linear Layout

本文档中内容 
IN THIS DOCUMENT

  1. 布局权重 
    Layout Weight
  2. 演示样例 
    Example

关键类
KEY CLASSES

  1. 线性布局 
    LinearLayout
  2. 线性布局.布局參数
    LinearLayout.LayoutParams

线性布局 是一个视图分组。它在单一方向上对齐全部的子视图,或者竖直方向或者水平方向。能够使用  android:orientation  属性来指定布局方向。


LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

线性布局的全部子视图是按一个挨一个地堆叠。所以一个竖向列表每行仅仅会有一个子视图,不管多宽;水平列表仅仅有一行高(最高子视图的高度,加上内填充)。

线性布局遵守子视图间的外边距以及每个子视图的重力(靠右、居中或靠左)。
All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each child.

布局权重
Layout Weight


线性布局还支持通过属性 android:layout_weight 给各个子视图赋一个权重值。

这个属性依照顾该在屏幕上占有多少空间来给一个视图赋一个权重值。更大的权重值将同意它扩展以填充父视图中剩余的空间。子视图能够指定一个权重值,这样一来全部余下的视图组空间都会分配给声明了权重的那部分子视图。默认值是 0 。
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.

比如。假设有三个文本哉。而且当中两个声明了 1 的权重,而还有一个没有给定权重,那么第三个没有权重的文本域不会增长,仅仅会占用其内容必需的区域(待測试:假设未指定权重而指定了宽或高,那么内容必需的区域是指实际内容还是宽、高值?还是通过 onMeasured 方法获得该视图的内容必需的区域?)。其他两个域就会平等地填充在全部三个域測量后余下的空间。假设第三个字段随后给定了一个 2 的权重(而不是 0 了)。那么它如今声明的比其他两个权重更重了。这样它获得总共余下空间的一半,而头两个等分余下的部分。
For example, if there are three text fields and two of them declare a weight of 1, while the other is given no weight, the third text field without weight will not grow and will only occupy the area required by its content. The other two will expand equally to fill the space remaining after all three fields are measured. If the third field is then given a weight of 2 (instead of 0), then it is now declared more important than both the others, so it gets half the total remaining space, while the first two share the rest equally.

样例
Example


<?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:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>

有关线性布局每个子视图可用的属性的具体描写叙述,能够查看 LinearLayout.LayoutParams 。
For details about the attributes available to each child view of a LinearLayout, seeLinearLayout.LayoutParams.








相关文章:

  • hexo 添加标签
  • 重载()运算符和重载强制类型转换
  • 配置openssh实现sftp远程文件上传
  • 单反相机学习资料
  • 正则表达式
  • Node.js + Express 4.x + MongoDB 构建登录注册(二)
  • VMware NAT模式
  • 无锡换社保卡的流程(旧社保卡在手上)
  • vim安装
  • iOS 中 iBeacon 开发
  • Kali-linux控制Meterpreter
  • HTTP响应状态码
  • 开源中文分词工具探析(六):Stanford CoreNLP
  • 用脚本模式配置数据同步
  • 如何在ubuntu16上安装docker
  • Facebook AccountKit 接入的坑点
  • Java的Interrupt与线程中断
  • js正则,这点儿就够用了
  • KMP算法及优化
  • Mybatis初体验
  • MySQL几个简单SQL的优化
  • PAT A1120
  • PHP 7 修改了什么呢 -- 2
  • Python打包系统简单入门
  • scrapy学习之路4(itemloder的使用)
  • SegmentFault 社区上线小程序开发频道,助力小程序开发者生态
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 使用Swoole加速Laravel(正式环境中)
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • 我们雇佣了一只大猴子...
  • 组复制官方翻译九、Group Replication Technical Details
  • #gStore-weekly | gStore最新版本1.0之三角形计数函数的使用
  • #宝哥教你#查看jquery绑定的事件函数
  • (C语言)编写程序将一个4×4的数组进行顺时针旋转90度后输出。
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (Python) SOAP Web Service (HTTP POST)
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (原創) X61用戶,小心你的上蓋!! (NB) (ThinkPad) (X61)
  • (原創) 人會胖會瘦,都是自我要求的結果 (日記)
  • (转)socket Aio demo
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .NET 服务 ServiceController
  • .NET 中创建支持集合初始化器的类型
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET成年了,然后呢?
  • .NET框架类在ASP.NET中的使用(2) ——QA
  • .NET正则基础之——正则委托
  • .NET中 MVC 工厂模式浅析
  • @hook扩展分析
  • [2]十道算法题【Java实现】
  • [20150321]索引空块的问题.txt