所有View(视图)元素中都有一个XML属性android:layout_weight,其值为0,1,2,3...等整数值。使用了之后,其对应界面中的元素比例就会发生变化,变大或者变小。layout_weight属性其实就是一个元素重要度的属性,用于在线性布局中为不同的view元素设置不同的重要度。
所有的视图都有一个layout_weight值,其默认值为0,表示视图多大就占据多大的屏幕空间。若赋一个>0的数值,则各视图元素将会把父视图中的可用空间进行分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
比如:说我们在水平方向两个文本标签(TextView),两个文本标签各自并指定layout_weight值为1,则各占一半,一个是1,一个2,则一个占2/3屏幕,一个占1/3。
需要注意的是:layout_weight值越小其重要度越高,占用屏幕越大。
layout_weight用于给一个线性布局中的诸多视图的重要度赋值。所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空
间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
ayout_weight is used in LinearLayouts to assign "importance" to Views within the layout. All Views have a default layout_weight of zero, meaning they take up only as much room on the screen as they need to be displayed. Assigning a value higher than zero will
split up the rest of the available space in the parent View, according to the value of each View's layout_weight and its ratio to the overall layout_weight specified in the current layout for this and other View elements.
To give an example: let's say we have a text label and two text edit elements in a horizontal row. The label has no layout_weight specified, so it takes up the minimum space required to render. If the layout_weight of each of the two text edit elements is set
to 1, the remaining width in the parent layout will be split equally between them (because we claim they are equally important). If the first one has a layout_weight of 1 and the second has a layout_weight of 2, then one third of the remaining space will be
given to the first, and two thirds to the second (because we claim the second one is more important).
分享到:
相关推荐
layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要,下面为大家介绍下具体的使用方法
详细介绍了Android驱动开发流程,以及相应的Android开发实例以及跨平台
Android布局详解 RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 android:layout_...
Android系统原理及开发要点详解_韩超_梁泉_带书签
android属性详解 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_below 将该控件的底部置于给定ID的控件之下; android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
多图详解Android_2.3_SDK安装教程
android_TextView的属性的见解和用法
你了解Android Layout中的属性没?你清楚在layout中用什么属性没,不用担心,这里告诉你啦
android驱动开发,linux驱动开发
多图详解Android_2.3_SDK安装教程
Android_SDK2.2__开发环境详解
Android应用开发详解_源码.rar Android应用开发详解_源码.rar
主要是针对android初学者对于android的layout布局不是很清楚的人
Android_SDK2.2__开发环境详解
android应用开发详解_源码(全2-18),包括全部源码,赶紧下载哦。。。
android中对weight的学习可以说是必须的,如果UI布局仅仅使用dp与sp等等,会让布局显得极度不灵活,毕竟各个手机屏幕大小不同,更别说是还有ipad之类的了,所以也是同做本人近期做的一个小UI来分享一下weight的使用...
Android系统原理与开发要点详解_培训课件下载。 Android系统原理与开发要点详解_培训课件下载。 Android系统原理与开发要点详解_培训课件下载。 Android系统原理与开发要点详解_培训课件下载。 Android系统原理与...
android应用开发详解_源代码 和android应用开发详解配套的教程