一、
Layout_weight:weigth的意思是“权值”
这个属性可以设置控件在父布局中的所占比重。
二、
特别注意:Layout_weight的使用前提是父布局还有空余空间。分配父布局剩余的空间,而不是父布局的所有空间。这一点可能在学习的过程中会被一些资料误导。见图中控件One和控件Two
1、假设有两个控件,分别设置它们的Layout_weight值为1,则这两个控件会平分父布局剩余空间。而不是平分父布局的所有空间。见图中控件One和控件Two
2、假设分别设置控件一的Layout_weight的值为1,控件二的Layout_weight的值为2,那么父布局剩余的空间控件一占一份,控件二占两份。显示的效果是控件一的宽和高加上所得的一份空间的宽和高
3、如果想要设置控件一和控件二在父布局中宽的比例是1:2。
方法:将控件一和空间二的宽设置为0dp,设置控件一的Layout_weight的值为1,控件二的Layout_weight的值为2。就可以实现。其它多个控件的比例实现也是类似的。
XMl代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One的宽是0dp权值为1,Two的宽是200dp权值为1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00ff"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="One" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Two" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three的宽是0dp权值为1,Four的宽是0dp权值为2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ffff"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Three" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Four" />
</LinearLayout>
</LinearLayout>
分享到:
相关推荐
dellR210服务器 window2008服务器安装系统需要驱动程序,dell阵列卡磁盘驱动文件,可放置在U盘安装系统识别驱动
ERP系统信息化资料:SAP专业教材资料A05_上线说明会.ppt
OpenGL的开天辟地源码,用VC++6.0和OpenGL编写的开天辟地,三维的天空和地形
1、错误1(1)错误现象测试点0pass之后读取数据一直xxx(2)分析定位过程有Z调Z,有X调X,发现inst和data的ok信号一直是0(3)错误原因逻辑出
按图索骥学-机器学习 有关机器学习的一组教程,深入浅出 用一副思维导图串联所有学习资源和知识点,每个同学都可以根据自己的情况,按图索骥,设计自己的学习路径,学习需要的课程 有关此课程详细信息,请访问...
DELL R720 2008R2_64位系统网卡驱动
6.STM8S-A05_ADC单次软件触发 7.STM8S-A05_ADC连续转换 8.STM8S-A06_AWU自动唤醒(未校正LSI时钟) 9.STM8S-A06_AWU自动唤醒(已校正LSI时钟) 10.STM8S-A07_内部EEPROM编程 11.STM8S-A07_内部FLASH编程 12.STM8S-...
最近在朋友买了一个二手的DELL C1100(CS24-TY) 机架式服务器。 注意CS24-TY是DELL C1100的定制型号,和标准版的有所不同。但是网上玩家已经试出了更新标准版BIOS和BMC的方法(见下面英文介绍的步骤)。...
学OpenGL编3D游戏_CAI
LSI 3081E-R 8口PCI-E阵列卡 sas card sas卡
Dism++是由微软内部API编写的一个系统精简工具,拥有强大的系统精简修复处理功能。Dism++支持多种系统清理项目,能全方位保障电脑的最佳运作状态。Dism++目前已适配全部Windows操作系统。
戴尔灵越1440蓝屏不用怕,有我为你解决。
P298_M6225J_0815A05_V11CN_FAT.bin
<br/> 目录: A01_OpenGL的程序框架 A02_OpenGL的基本图形 A03_OpenGL的组合图形 A04_摄像漫游 A05_开天辟地 A06_OpenGL中显示文字 A07_特殊的平面_树 A08_显示3D模型 A09_MD2动画模型...
A05_开天辟地 第5 章源程序 A06_OpenGL中显示文字 第6 章源程序 A07_特殊的平面_树 第7 章源程序 A08_显示3D模型 第8 章源程序 A09_3D动画 第9 章源程序 A10_射击、爆炸 第10章源程序 A11_碰撞检测 第11章源程序 A12...
集成阵列卡,DELL_MULTI-DEVICE_A05_R294489
SAS-RAID_Driver_6V4WY_WN64_6.604.06.00_A05.EXE
数学建模-07cumcm_a05.zip
几个3d游戏的源码包括:A01_OpenGL的程序框架,A04_摄像漫游,A05_开天辟地,A07_特殊的平面_树,A09_MD2动画模型,A12_碰撞检测,对3d游戏编程初学者有很大作用。
A05_开天辟地 第5 章源程序 A06_OpenGL中显示文字 第6 章源程序 A07_特殊的平面_树 第7 章源程序 A08_显示3D模型 第8 章源程序 A09_3D动画 第9 章源程序 A10_射击、爆炸 第10章源程序 A11_碰撞检测 第11章源...