对android LinearLayout中layout_weight属性使用初探

首先引用这篇文章:http://sinye.iteye.com/blog/1068204

文中对layout_weight的使用环境进行了描述,我总结一下,这是我的测试条件:

1,控件所在layout必须是LinearLayout。

2,LinearLayout的orientation属性设置成“horizontal”。

3,子控件的layout_width属性设置为“fill_parent”。

1,两个子控件,1:1

xml:

1 < LinearLayout android:id ="@+id/custom_titlebar"
2 xmlns:android ="http://schemas.android.com/apk/res/android"
3 android:orientation ="horizontal"
4 android:layout_width ="fill_parent"
5 android:layout_height ="wrap_content" >
6
7 < Button android:id ="@+id/imageViewLoginState"
8 android:layout_width ="fill_parent"
9 android:layout_height ="fill_parent"
10 android:layout_weight ="1" ></ Button >
11
12 < Button android:id ="@+id/imageViewLoginState1"
13 android:layout_width ="fill_parent"
14 android:layout_height ="fill_parent"
15 android:layout_weight ="1" ></ Button >
16   </ LinearLayout >

效果很明显,1:1

2,两个子控件,1:2

xml:

< LinearLayout android:id ="@+id/custom_titlebar"
xmlns:android
="http://schemas.android.com/apk/res/android"
android:orientation
="horizontal"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content" >

< Button android:id ="@+id/imageViewLoginState"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:layout_weight
="1" ></ Button >

< Button android:id ="@+id/imageViewLoginState1"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:layout_weight
="2" ></ Button >
</ LinearLayout >

效果很明显,2:1

3,三个子控件,1:1:1

xml不再贴了,效果很明显,1:1:1

4,三个子控件,1:1:2(好戏来了)

xml:

< LinearLayout android:id ="@+id/custom_titlebar"
xmlns:android
="http://schemas.android.com/apk/res/android"
android:orientation
="horizontal"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content" >

< Button android:id ="@+id/imageViewLoginState"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:text
="button1"
android:layout_weight
="1" ></ Button >

< Button android:id ="@+id/imageViewLoginState1"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:text
="button2"
android:layout_weight
="1" ></ Button >

< Button android:id ="@+id/imageViewLoginState2"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:text
="button3"
android:layout_weight
="2" ></ Button >
</ LinearLayout >

效果很奇怪,你能猜到吗:

怪处有二:1,button3消失了。2,button1、button2变成了胖子(经测量,高度是原来的两倍)。

4,三个子控件,2:1:2

xml不再贴了,效果依然很怪异:

实在不好意思,能力有限,贴到这里,我还没有总结出规律,先到此为止吧,您有什么好建议,可以发给我。

转载于:https://www.cnblogs.com/tara/archive/2011/06/30/2094136.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值