android 59 LinearLayout 线性布局

##常见的布局
* LinearLayout 线性布局
线性布局往左右拉是拉不动的,
> 线性布局的朝向 vertical|horizontal
> 线性布局的权重 weight 和 0dip一起使用

复制代码
<?xml version="1.0" encoding="utf-8"?>
<!-- 线性布局控件自上而下整齐的排列 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >  垂直排列,里面的内容垂直排列

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"  高度为0,则高度根据权重来占比例,
        android:layout_weight="1"  权重为1,则高度为权重和的1份即1/3,权重只能跟为0的宽度或高度,
        android:text="按钮1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:text="按钮2" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:text="按钮3" />

</LinearLayout>
复制代码
复制代码
<?xml version="1.0" encoding="utf-8"?>
<!-- 线性布局控件自左向右整齐的排列 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >   水平排列,不用权重则多的将会挤出去,

    <Button
        android:layout_width="0dip"  宽度为0,
        android:layout_height="wrap_content"  高度填充父窗体,和父组件宽度一样宽,
        android:layout_weight="2"    权重为2,则宽度为权重和的2份即2/4,权重只能跟为0的宽度或高度,
        android:text="按钮1" />

    <Button
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"   权重为1,则宽度为权重和的1份
        android:text="按钮2" />

    <Button
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"        权重为1,则宽度为权重和的1份
        android:text="按钮3" />

</LinearLayout>
复制代码

 

 以上的代码:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >   最外层是线性布局,垂直排列

    <LinearLayout
        android:orientation="horizontal"     里面是水平排列
        android:layout_width="match_parent"  宽度为父窗体宽度
        android:layout_weight="1"       权重为1
        android:layout_height="0dip" >  写0可以用权重了
        <TextView 
               android:layout_width="0dip"      宽度为0
        android:layout_height="fill_parent"     高度为父窗体
        android:layout_weight="1"              宽度权重为1
            android:background="#ff0000"
            />
        <TextView 
               android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
            android:background="#00ff00"
            />
        <TextView 
               android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
            android:background="#0000ff"
            />
        
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"     里面垂直排列
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip" >
          <TextView 
               android:layout_width="fill_parent"   宽度为父窗体
        android:layout_height="0dip"        高度为0
        android:layout_weight="1"           高度权重为1
            android:background="#ff0000"
            />
        <TextView 
               android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
            android:background="#00ff00"
            />
        <TextView 
              android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
            android:background="#0000ff"
            />
        
        
    </LinearLayout>

</LinearLayout>
复制代码

 


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/4915477.html,如需转载请自行联系原作者


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值