使用第三方WheelView制作日期选择器

需求:实现一年月日选择器,默认为当前日期,三者联动,并且在切换年月时,根据是否闰年或者月份天数动态改变日。多说无益,请看下图:

这里写图片描述

使用的第三方库(https://github.com/helloJp/WheelView)
此库可兼容到低版本,定制性很强,获取选中数据很方便。详情请戳链接,感谢helloJp的分享。

activity_main.xml放置一个封装好WheelView的自定义控件,没有什么自定义属性

<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"
    tools:context=".MainActivity">


    <test.oubowu.com.datepicker.DatePicker
        android:id="@+id/birthday_picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="5dp"
        android:gravity="center_horizontal" />

</RelativeLayout>

date_picker.xml线性布局放置三个WheelView,分别对应年月日:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/rectangle_bg"
    android:padding="2dp"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    >

    <test.oubowu.com.datepicker.WheelView
        android:id="@+id/year"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        app:itemNumber="5"
        app:lineColor="@android:color/darker_gray"
        app:lineHeight="2dp"
        app:maskHight="32dp"
        app:noEmpty="true"
        app:normalTextColor="@color/material_green_300"
        app:normalTextSize="14sp"
        app:selectedTextColor="@color/material_light_blue_a700"
        app:selectedTextSize="22sp"
        app:unitHight="50dp"
        />

    <test.oubowu.com.datepicker.WheelView
        android:id="@+id/month"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        app:itemNumber="5"
        
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值