android layout_weight 使用总结
今天在使用androidlayout_weight的时候遇到点奇怪的问题,就上网查了一下,发现这篇文章很详细,就转了过来,谢谢分享者,写的很详细。
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#00aa00"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#0000aa"
android:gravity="center"
android:text="1"/>
</LinearLayout>
效果图:

android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center"
android:text="1111111111111111111111111111111111111111111"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#00aa00"
android:gravity="center"
android:text="2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#0000aa"
android:gravity="center"
android:text="3"/>
</LinearLayout>

android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center"
android:text="1111111111111111111111111111111111111111111"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#00aa00"
android:gravity="center"
android:text="2"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#0000aa"
android:gravity="center"
android:text="3"/>
</LinearLayout>

android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#00aa00"
android:gravity="center"
android:text="2"/>
</LinearLayout>

android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#00aa00"
android:gravity="center"
android:text="2"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#0000aa"
android:gravity="center"
android:text="3"/>
</LinearLayout>
效果:


按比例显示LinearLayout内各个子控件,需设置 android:layout_width="0dp",如果为竖直方向的设置android:layout_height="0dp"。在这种情况下某 子个控件占用LinearLayout的比例为:本控件weight值 / LinearLayout内所有控件的weight值的和。
http://hunankeda110.iteye.com/blog/1879410
android layout_weight 使用总结的更多相关文章
- 【Android学习】android:layout_weight的用法实例
对于android:layout_weight的用法,用下面的例子来说明: <LinearLayout xmlns:android="http://schemas.android.co ...
- android:layout_weight的真实含义(转)
首先声明只有在Linearlayout中,该属性才有效.之所以Android:layout_weight会引起争议,是因为在设置该属性的同时,设置android:layout_width为wrap_c ...
- android layout_weight讲解
Layout_weight是线性布局,也就是LinearLayout里面用到的,下面通过实验来看这个Layout_weight的特性. 1.当控件的属性android:layout_width=&qu ...
- Android layout_weight的用法
android:layout_weight是指LinearLayout先给里面的控件分配完大小之后剩余空间的权重. 下面通过举例说明: <LinearLayout xmlns:android=& ...
- Android开发(二十七)——android:layout_weight的真实含义
android:layout_weight的真实含义是:一旦View设置了该属性(假设有效的情况下),那么该 View的宽度等于原有宽度(android:layout_width)加上剩余空间的占比! ...
- Android的LinearLayout中的权重android:layout_weight
当前EditText和Button部件只是适应了他们各自内容的大小,如下图所示: 这样设置对按钮来说很合适,但是对于文本框来说就不太好了,因为用户可能输入更长的文本内容.因此如果能够占满整个屏幕宽度会 ...
- android:layout_weight的真实含义
首先声明只有在Linearlayout中,该属性才有效.之所以android:layout_weight会引起争议, 是因为在设置该属性的同时,设置android:layout_width为wrap_ ...
- android:layout_weight越大所占比例越大和越大所占比例越小的两个例子
摘要: 我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3907146.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的 ...
- android:layout_weight总有你不知道的用法.
都知道weight是权重的意思. 在布局中起到非常重要的作用. 但是这玩意不能嵌套使用, 而且只能使用在LinearLayout中. 下面说说它的几种用法(以下例子全为横排 注意android:lay ...
随机推荐
- Spring处理器
Spring容器内部工作机制 Spring的AbstractApplicationContext是ApplicationContext抽象实现类,该抽象类的refresh()方法定义了Spring容器 ...
- HDU 3335
http://acm.hdu.edu.cn/showproblem.php?pid=3335 题意:在给出的n个数中找出一个集合,使得其中的数互不整除,求该集合最大的元素数量 首先要对输入的数去重,输 ...
- Visual Studio Usage
Navigation Double click on UI element goes to its _click event. F12 – for method or variable, go to ...
- 收集Magento FAQ常见问题处理办法
问题:Magento如何下载? 解答:Magento的英文官方下载地址为:http://www.magentocommerce.com/download 注意:需要注册后才可以下载,而且请下载完整版本 ...
- CentOS下Web服务器环境搭建LNMP一键安装包
CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...
- 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- ES6 — 新增关键字let、const
ECMAScript 是什么? 首先,我们都知道JavaScript由三部分组成:ECMAScript,DOM,BOM: 其中的ECMAScript是Javascript的语法规范. ECMAScri ...
- 软件工程课程作业(三)--四则运算3(C++)
伙伴链接:http://www.cnblogs.com/haoying1994/ 一.设计思路 在此前程序拥有的功能:加减有无负数,除法有无余数以及算式可定制的功能的基础上,此次程序又添加了算式结果的 ...
- phpmyadmin的安装和使用
首先在phpmyadmin的官方网站的下载页面根据自己的PHP以及MYSQL的版本下载对应的phpmyadmin版本. 图中红框部分标识此版本支持度额PHP版本以及MYADL版本. 比如此版本就是支持 ...