Android一共有5中布局:
1.线性布局LinearLayout
2.相对布局RelativeLayout
3.绝对布局AbsoluteLayout
4.帧布局FrameLayout
5.表格布局TableLayout
在这里我介绍的Android时间组件中用到了相对布局RelativeLayout
在Android中,有2个时间组件:TimePicker与DatePicker
TimePicker:安卓提供的时间组件,用于时分秒系统时间显示。
DatePicker:安卓提供的日期组件,用于年月日日期的时间显示。
代码如下:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TimePicker
android:id="@+id/timepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timepicker" />
</RelativeLayout>
在这里用到相对布局的时候就得将DatePicker组件设置在TimePicker组件的下方,否则2个组件会重叠在一起。
在安卓虚拟机上运行结果截图: