Android LinearLayout属性

LinearLayout 线性布局:既然是线性的,就有方向的问题。所以就得定义是分水平还是垂直

android:orientation="vertical" 定义为水平方向

android:orientation="horizontal" 定义为垂直方向

当然,你要是不定义的话,默认是垂直的。但是这种习惯不好。。。

还有什么常用的属性呢,,,

android:layou_weight="值" 分配权重 。使用这个属性时,该控件不需要去定义高度(即:android:layout_height="wrap_content")。这个值表示该控件对没有占用的空间的大小。

就比如:

<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="${relativePackage}.${activityClass}" >

    <TextView
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:text="@string/hello_world" />
    <Button 
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:text="@string/hello_world"/>

</LinearLayout>

你能很清楚的看到整个手机屏幕被TextView和Button各自占一半的空间。如果你把Button的layout_weight改成2,那就意味着整个LinearLayout的布局要分成3份,其中这个Button要占用2份的空间大小。总之,你要想把一块空间分割成几个小块,那你就可以使用这个属性了。


暂时就先这样吧。。。。。






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值