android布局之线性布局

本文详细介绍了Android应用开发中LinearLayout线性布局的基本概念,包括水平和垂直线性布局的区别,通过XML示例展示了如何在代码中实现这两种布局,并解释了它们在实际应用中的用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值