相对布局LinearLayout权重weight的用法

大家好,这是我第一次写博客,有什么不足的地方,请大家多多指教,我会虚心反思,每一次都能有所进步微笑。这次我给大家带来的是LinearLayout布局里的有关于权重weight相关知识,以及是怎样在LinearLayout中如何正确的使用。


首先什么都不说,先上这次代码运行成功后的图片。


这张图片的实现效果运用到的是LinearLayout中weight这个知识点,下面我为大家分析怎么使用weight权重。


第一种weight权重:

上半部分竖条的效果,三个大小一致的颜色不同的竖条,它使用LinearLayout把三个控件包裹起来,其中使用了android:orientation="horizontal" 属性,表示布局是水平排列的,

进而你就知道了,它是靠布局的宽来进行恒等分割,也就是权重的意思,而layout_width=设置为0dp,每个需要权重的布局都要加上android:layout_weight="1"属性。嗯,这样就o了,放代码给大家看看。


 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="#22ff0000"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1"
            android:background="#ff6600" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1"
            android:background="#ffffcc" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1"
            android:background="#ffff99" />
    </LinearLayout>


第二种weight权重:

下半部分横条的效果,要有这个效果LinearLayout设置属性为orientation="vertical" ,其他属性省略,垂直排列的,它是靠长来进行恒等分割的,而把 属性设置为android:layout_height="0dp",layout_width可以设置任意值,但不能为0,再加上 android:layout_weight="1",就可以执行上图效果了,。上代码,给大伙瞧瞧.....


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#ffff0000" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#33ff00" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#66ffff" />
       
       
    </LinearLayout>



谢谢大家不厌其烦的看完我第一次不完美的微博,不满意请留下你的评论,我会有则改之无则加勉,下次有更好的微博分享给大家。







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值