`

7.2 LinearLayout布局详解

阅读更多
LinearLayout线性布局,线性布局是所有布局中最常用的,它可以让其中的子元素垂直或水平的方式排列(通过排列方向的设置)。通常复杂的布局都是在LinearLayout布局中嵌套而成的。
下面看一个LinearLayout的例子,这个例子中有垂直和水平的嵌套使用,例子如下图7-12所示。
 


图7-12 LinearLayout
布局文件请参考代码清单7-14,完整代码请参考chapter7_2工程中linearlayout2.xml代码部分(chapter7_2/res/layout/linearlayout2.xml)。
【代码清单7-14】
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello"
		android:textSize="20dip" android:gravity="center" />
	<LinearLayout android:orientation="horizontal"
		android:layout_width="fill_parent" android:layout_height="wrap_content">
		<TextView android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="@string/user"
			android:textSize="15dip" />
		<EditText android:id="@+id/username" android:layout_width="fill_parent"
			android:layout_height="wrap_content"></EditText>
	</LinearLayout>
	<LinearLayout android:orientation="horizontal"
		android:layout_width="fill_parent" android:layout_height="wrap_content">
		<TextView android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="@string/pass"
			android:textSize="15dip" />
		<EditText android:id="@+id/password" android:layout_width="fill_parent"
			android:layout_height="wrap_content"></EditText>
	</LinearLayout>
	<LinearLayout android:orientation="horizontal"
		android:layout_width="fill_parent" android:layout_height="wrap_content">
		<Button android:text="@string/loginbtn" android:id="@+id/Button01"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
		<Button android:text="@string/registerbtn" android:id="@+id/Button02"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
	</LinearLayout>
</LinearLayout>

                                                                  出自《Android开发案例驱动教程》第七章
  • 大小: 14.4 KB
分享到:
评论

相关推荐

    最新版Android开发教程7.2.pdf

    ### Android编程基础知识点详解 #### 一、隐藏标题栏与状态栏 在Android应用程序开发过程中,根据用户界面设计的需求,有时需要对应用的显示效果进行调整,比如隐藏标题栏或状态栏来达到全屏显示的效果。 ##### ...

    Android入门到精通源代码.

    6.2.2 线性布局(LinearLayout) 6.2.3 相对布局(RelativeLayout) 6.2.4 表格布局(TableLayout) 6.2.5 绝对布局(AbsoluteLayout) 6.3 界面中的字体 6.3.1 设置系统字体 6.3.2 引用用户自定义字体 6.4 应用实例...

    android开发资料

    - **4.3.1 垂直线性布局**: 使用LinearLayout来组织控件,使它们垂直排列。 - **4.3.2 水平线性布局**: 同样使用LinearLayout,但这次使控件水平排列。 - **4.3.3 相对布局(RelativeLayout)**: 控件之间的位置关系...

    Android实例代码

    2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本界面组件:TextView、EditText; Button、ImageButton; 9Patch; RadioButton、CheckBox; ToggleButton;AnalogClock、...

    疯狂Android讲义(第2版)源代码 第6章~第9章

    2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本界面组件:TextView、EditText; Button、ImageButton; 9Patch; RadioButton、CheckBox; ToggleButton;AnalogClock...

Global site tag (gtag.js) - Google Analytics