Android LinearLayout的android:layout_weight属性
android:layout_weight为大小权重,相当于在页面上显示的百分比,它的计算是根据LinearLayout中所有相关元素的此属性值计算的。
除了已经固定大小的,其他设置了此属性的view所占大小(长度或高度)为自己layout_weight属性值/所有layout_weight属性值*总大小。这个属性在android的sdk中都没有介绍。下面举例介绍下
比如在一个layout中显示3个TextView,第一个TextView长度占20%,第二个长度占50%,第三个占长度30%,
则比例为20%:50%:30%=2:5:3。layout代码如下
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="2"
- android:layout_alignParentLeft="true"
- android:gravity="center_vertical"
- android:text="文本1" />
- <TextView android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="5"
- android:layout_alignParentLeft="true"
- android:gravity="center_vertical"
- android:text="文本2" />
- <TextView android:id="@+id/textView3"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="3"
- android:layout_alignParentLeft="true"
- android:gravity="center_vertical"
- android:text="文本3" />
- </LinearLayout>
从以上代码可以看出只需要设置各个TextView的android:layout_weight属性值为对应的比例即可
其中android:layout_alignParentLeft="true" android:gravity="center_vertical"是为了方便查看而设置
Android LinearLayout的android:layout_weight属性的更多相关文章
- Android:LinearLayout布局中Layout_weight的深刻理解
首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重.很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间. 看下面代码 ...
- Android开发工程师文集-layout_weight讲解
前言 大家好,给大家带来Android开发工程师文集-layout_weight讲解的概述,希望你们喜欢 Layout_weight的相关代码展示 <TextView android:layou ...
- 神奇的layout_weight属性
1.概述 在线性布局有时候为了控制一下屏幕的适配,可以使用layout_weight这个属性来设置权重,要注意一点,这个属性只有在Linearlayout中才有效,这个属性往往会随着android:l ...
- Android 布局学习之——LinearLayout的layout_weight属性
一直对layout_weight属性感到比较困惑,今天学习一下,来深入了解layout_weight属性和它的用法. 定义 首先,看看Android官方文档是怎么说的,毕竟人家才是权威 ...
- Android UI: LinearLayout中layout_weight 属性的使用规则
首先来查看android sdk文档,有这么一段话 LinearLayout also supports assigning a weight to individual children with ...
- android:layout_weight属性详解 (转)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...
- android:layout_weight属性详解(转)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...
- android LinearLayout android:layout_weight 作用,固定比例
android 中的 LinearLayout 是线性布局有水平布局horizontal 垂直布局vertical .本文针对 水平布局horizontal 布局的weight属性做一个标记,以免 ...
- 50一个Android开发技巧(01 利用好layout_weight属性)
问题:如何将一个Button放置在布局的中间,并设置其宽度parent的50%? 分析:问题想要达到的效果应该是这样: (原文地址:http://blog.csdn.net/vector_yi/art ...
随机推荐
- [leetcode]Flatten Binary Tree to Linked List @ Python
原题地址:http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ 题意: Given a binary tree, fl ...
- 关于asp.net页面缓存
1,ASPX页面缓存 页面缓存的使用方法非常的简单,只需要在aspx页的顶部加一句声明<%@ OutputCache Duration="60" VaryByParam=&q ...
- Merge Sorted Array leetcode java(回顾MergeTwoArray和MergeTwoLinkedList)
题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...
- C#中图片切割,图片压缩,缩略图生成的代码
**//// <summary> /// 图片切割函数 /// </summary> /// <param name="sourceFile"> ...
- 以上帝模式管理Windows系统
上帝模式,,即"God Mode",或称为"完全控制面板".是Windows Vista/7系统中隐藏的一个简单的文件夹窗口,但包含了几乎所有Windows系统 ...
- 转:好用 Eclipse插件收集与说明
http://developer.51cto.com/art/201007/214478.htm
- System.ComponentModel.Component : MarshalByRefObject, IComponent, IDisposable
#region 程序集 System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Windows\ ...
- CSS半透明兼容写法
filter: Alpha(opacity=10); -moz-opacity:0.1; opacity:0.1; 例如: background:#A5CD40; filter: Alpha(opac ...
- LuaCURL
LuaCURL:http://luacurl.luaforge.net/ curl大家应该都知道吧,在linux下被广泛使用,也有windows版本,网络上还有其win32版本的源代码.它是一个命令行 ...
- uploadify的java应用
API:http://www.uploadify.com/documentation/ 下载地址:http://www.uploadify.com/ 这几天查看插件,发现uploadify插件做不错, ...