weight:重量、权重。

  当我们给一个view设置了android:layout_weight属性,意味着赋予它话语权,常规思维就是谁的weight大,谁说了算(空间占比大)。

  下面我们来看下具体的代码:

  

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="我的weight是2"
android:layout_weight="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的weight是1"
android:layout_weight="1"/> </LinearLayout>

两个Button的宽度设置的是wrap_content,此时weight属性使LinearLayout给内部的两个Button按2:1的权重分配了所有宽度空间。

官方推荐使用weight按比例分配宽度空间时,将LinearLayout内View的宽度设置为0。

android:layout_weight属性详解的更多相关文章

  1. android:layout_weight属性详解 (转)

    在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...

  2. android:layout_weight属性详解(转)

    在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...

  3. android:exported 属性详解

    属性详解 标签: android 2015-06-11 17:47 27940人阅读 评论(7) 收藏 举报 分类: Android(95) 项目点滴(25) 昨天在用360扫描应用漏洞时,扫描结果, ...

  4. Android weight属性详解

    android:layout_weight是一个经常会用到的属性,它只在LinearLayout中生效,下面我们就来看一下: 当我们把组件宽度设置都为”match_parent”时: <Butt ...

  5. 【转】android布局属性详解

    LinearLayout布局: 线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的.在这个界面中,我们应用了一个 LinearLayout的布局,它是垂直向下扩展的 ,所以创建的布局XML ...

  6. android 布局属性详解

    Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料. 第一类:属性值为true或falseandroid:layout_centerHrizontal ...

  7. android布局属性详解

    RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal  水平居中 android:layout_cen ...

  8. Android布局属性详解剖析

    View的布局显示方式有下面几种: 线性布局(LinearLayout) 相对布局(RelativeLayout) 表格布局(TableLayout) 网格视图(GridView) 标签布局(TabL ...

  9. android TextView属性详解

    RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false     android:layout_centerHrizontal  水平居中      android:l ...

随机推荐

  1. python_重写数组

    class MyArray: '''All the elements in this array must be numbers''' def __IsNumber(self,n): if not i ...

  2. codeforces 983B XOR-pyramid

    题意: 定义一个函数f(a): 给出一个数组a,有q个询问,每次询问回答在l到r的区间内,连续子串的f函数的最大值. 思路: 画图,来自codeforces SheepRanger 由此图可知,f(l ...

  3. 高质量的内容是SEO的关键

    内容是最有效的SEO策略,但也是最难执行的 正确的目录对SEO(搜索引擎优化:search engine optimization)关乎重大.根据Ascend2在2014年4月对全球营销专业人士做的调 ...

  4. Java操作Memcached

    本文复制其他播客,有好的技术文章希望各位大神能告知... 谢谢. 如何使用Java操作Memcached实例: 代码一: package com.ghj.packageoftool; import j ...

  5. PAT1113: Integer Set Partition

    1113. Integer Set Partition (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  6. PHP开发基础知识

    PHP的学习 PHP脚本以<?php 开始 ?>结束 <?php //此处写代码 ? > php默认文件扩展名.php php文件通常包含HTML标签以及一些PHP脚本代码 “ ...

  7. 在Mac OS X中配置Apache + PHP + MySQL 很详细

    这是一篇超级详细的配置mac os下面php+mysql+apache的文章.非常详细我的大部分配置就是参考上面的内容的,比如,PHP不能连接数据库,就是改一下默认的php.ini中pdo_mysql ...

  8. stats.go

    , len(c.clients))             for _, client := range c.clients {                 clients = append(cl ...

  9. MySQL 在线更改 Schema 工具

    MySQL在线更改schema的工具很多,如Percona的pt-online-schema-change. Facebook的 OSC 和 LHM 等,但这些都是基于触发器(Trigger)的,今天 ...

  10. 排序1,2......n的无序数组,时间复杂度为o(n),空间复杂度为o(1)

    #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _T ...