android布局之线性布局

LinearLayout 线性布局有两种,分别是水平线性布局和垂直线性布局,LinearLayout属性中android:orientation为设置线性布局当其="vertical"时,为 垂直线性布局,当其="horizontal"时,为水平线性布局,不管是水平还是垂直线性布局一行(列)只能放置一个控件。

下面我们举例说明:

垂直线性布局

<?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" >

    <EditText 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        
        />
    
    <Button 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Button1"/>

    <Button 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="button2"/>

</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" >
    
    <EditText 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        />
    
    <Button 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Button1"/>

    <Button 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="button2"/>

</LinearLayout>

运行结果:



这两种线性布局唯一的差别就是android:orientation的值不同,垂直线性布局的值为vertical ,水平线性布局的值为"horizontal"

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值