安卓布局与安卓时间组件TimePicker和DatePicker

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个组件会重叠在一起。

在安卓虚拟机上运行结果截图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值