Android布局笔记

一.关于layout_weight的用法:
1.如果要在水平方向按比例(比如1:3)分配:
各个组件的宽度设为0dp
第一个组件的layout_weight=1//宽度占屏幕剩余宽度的四分之一
第二个组件的layout_weight=3//宽度占屏幕剩余宽度的四分之一
layout_weight默认为0,表示按自身给定的宽度布局
2.如果要让一个组件铺满剩余的空间(例如垂直方向)
那个其它组件保持默认值,设置这个组件的layout_weight值为1
高度任意。
还有两种方法是使用相对布局:
<RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content" >

       <Button
           android:id="@+id/bt9"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:text="按钮9" />

       <Button
           android:id="@+id/bt10"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_toLeftOf="@+id/bt11"
           android:layout_toRightOf="@+id/bt9"
           android:text="按钮10" />

       <Button
           android:id="@+id/bt11"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentRight="true"
           android:text="按钮11" />
   </RelativeLayout>

和使用表格布局:
<TableLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:stretchColumns="1"<!--第1列可伸展(序号从0开始)-->
   >

   <TableRow>

       <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="按钮1" />

       <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="按钮2" />
        <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="按钮3" />
   </TableRow>

</TableLayout>


本文出自 “Focus_000” 博客,转载请与作者联系!

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值