首页 > 移动平台 > 详细

android多设备界面适配的利器:属性weight的妙用

时间:2014-01-16 21:44:27      阅读:484      评论:0      收藏:0      [点我收藏+]

1、按比例显示控件元素

bubuko.com,布布扣
    <EditText
        android:id="@+id/edit_message"
        android:layout_weight="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" >
        <requestFocus />
    </EditText>
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/button_send" />
bubuko.com,布布扣


属性weight的作用(不翻了,将就看吧):

if you give one view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 of the remaining space and the second view fills the rest. If you add a third view and give it a weight of 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remaining two each get 1/4.

EditText 占 2/3  ,  Button 占 1/3. 

 

bubuko.com,布布扣

注意:只有当这两个控件的layout_width、layout_height都设置为"wrap_content"时,这个规则才能够成立。

2、一个控件独占,其它控件根据自身内容自动调整。

将需要独占的控件,其weight设置为1,同时宽度设置为0dp。根据自身内容调整的控件,不要设置weight。

bubuko.com,布布扣

效果:

bubuko.com,布布扣

android多设备界面适配的利器:属性weight的妙用

原文:http://www.cnblogs.com/ygm900/p/3521328.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!