Android的线性布局方式

本文详细介绍了Android开发中两种基本的线性布局——水平线性布局和垂直线性布局,并通过具体的XML代码示例展示了这两种布局的应用方式及其关键属性。

计应111班 陈佳

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

水平线性布局:

01.<?xml version="1.0" encoding="utf-8"?> 
02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
03.    android:layout_width="match_parent" 
04.    android:layout_height="match_parent" 
05.    android:orientation="horizontal" > 
06.     
07.    <EditText  
08.        android:layout_width="100dp" 
09.        android:layout_height="wrap_content" 
10.        /> 
11.     
12.    <Button  
13.        android:layout_width="100dp" 
14.        android:layout_height="wrap_content" 
15.        android:text="Button1"/> 
16. 
17.    <Button  
18.        android:layout_width="100dp" 
19.        android:layout_height="wrap_content" 
20.        android:text="button2"/> 
21. 
22.</LinearLayout>

运行结果:

垂直线性布局:

01.<?xml version="1.0" encoding="utf-8"?> 
02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
03.    android:layout_width="match_parent" 
04.    android:layout_height="match_parent" 
05.    android:orientation="vertical" > 
06. 
07.    <EditText  
08.        android:layout_width="100dp" 
09.        android:layout_height="wrap_content" 
10.         
11.        /> 
12.     
13.    <Button  
14.        android:layout_width="100dp" 
15.        android:layout_height="wrap_content" 
16.        android:text="Button1"/> 
17. 
18.    <Button  
19.        android:layout_width="100dp" 
20.        android:layout_height="wrap_content" 
21.        android:text="button2"/> 
22. 
23.</LinearLayout> 

总结:水平和垂直布局就在页面的分布上不同,其他都一样的

转载于:https://www.cnblogs.com/cc502/archive/2013/05/20/3088960.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值