Android的线性布局方式
计应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>
总结:水平和垂直布局就在页面的分布上不同,其他都一样的