本文实例为大家分享了Android实现滚动日期选择器的具体代码,供大家参考,具体内容如下
<强> wheelview滚动效果的视图强>
这段时间需要用到一个时间选择器,但是不能使用日期对话框,
因为它是筛选条件框架下的,只能是视图!这个WheelView改造后可以达到要求!
这个wheelview框架使用的类不多,就几个,还有一些资源文件。
我根据这个框架设计了日期的选择器。
主页面:
第一种日期选择器页面:
动态效果:
<强>使用:强>
具体的实现是一个LoopView的类,这是一个继承视图的类!
理解LoopView的公开方法就可以了。
1。布局文件
& lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:应用=" http://schemas.android.com/apk/res-auto " android:取向=按怪薄? android: layout_width=" match_parent " android: layout_height=" match_parent " android:背景=" # fff” 比; & lt; com.example.wheelview.loopview.LoopView android: layout_marginTop=" 50 dp” android: id=癅 + id/loopView” android: layout_width=" match_parent " android: layout_height=" 150 dp” 应用:awv_textsize=?8”/比; & lt;/LinearLayout>
2。控制代码
包com.example.wheelview.activity; 进口android.app.Activity; 进口android.content.Intent; 进口android.os.Bundle; 进口android.view.View; 进口android.widget.Toast; 进口com.example.wheelview.R; 进口com.example.wheelview.loopview.LoopView; 进口com.example.wheelview.loopview.OnItemSelectedListener; 进口java.util.ArrayList; 公共类{MyActivity扩展活动 私人土司; @Override 保护空白>//中间选中的字体颜色:灰色:0 xff313131橙色:0 xffec6f1a centerTextColor=typedArray.getInteger (R.styleable。androidWheelView_awv_centerTextColor 0 xffec6f1a);//没被选中的字体的颜色 outerTextColor=typedArray.getInteger (R.styleable。androidWheelView_awv_outerTextColor 0 xffafafaf);//中间字体上下两条横线的颜色 dividerColor=typedArray.getInteger (R.styleable。androidWheelView_awv_dividerTextColor 0 xffc5c5c5);
其他的控制可以参考我的代码
我的项目的代码:wheelview滚动效果的View
我的代码中有一个时间的工具类,可以很方便的取到任何时间,你也可以在日期选择器中多加一个按钮,设置到今天的日期。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。