android布局之线性布局

来源:互联网 发布:房产中介辅助软件 编辑:程序博客网 时间:2024/06/05 18:01

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"

原创粉丝点击