WheelView
性能盘点:
1、绘制优化(绘制条数 = 显示条数 + 2,不会过多绘制)
2、支持各种数据类型(数据类型实现IWheel接口)
3、封装了多列底部弹窗
4、封装了日期时间选择底部弹出
效果截屏
wheel_view
column_dialog
date_time_dialog
简析源码
本篇就不做源码分析了
使用示例
1、属性
WheelView
{@link R.styleable#WheelView_wheelTextColor}// 文字颜色{@link R.styleable#WheelView_wheelTextSize}//文字大小{@link R.styleable#WheelView_wheelShowCount}//显示条数(高度由显示条数决定){@link R.styleable#WheelView_wheelTotalOffsetX}//文字在X轴方向偏移总量,0就不偏移、>0向右偏移并形成文字倾斜角度、<0向左偏移并形成文字倾斜角度{@link R.styleable#WheelView_wheelItemVerticalSpace}//两个显示Item之间的间距
WheelItemView在WheelView基础上添加了中间的两条分割线view。
{@link R.styleable#WheelView_wheelTextColor}// 文字颜色{@link R.styleable#WheelView_wheelTextSize}//文字大小{@link R.styleable#WheelView_wheelShowCount}//显示条数(高度由显示条数决定){@link R.styleable#WheelView_wheelTotalOffsetX}//文字在X轴方向偏移总量,0就不偏移、>0向右偏移并形成文字倾斜角度、<0向左偏移并形成文字倾斜角度{@link R.styleable#WheelView_wheelItemVerticalSpace}//两个显示Item之间的间距{@link R.styleable#WheelItemView_wheelMaskLineColor}//中间两条线的颜色
2、gradle引用
[图片上传失败...(image-1a1472-1542887345559)]
compile 'jsc.kit.wheel:wheel-view:_latestVersion'
<jsc.kit.wheel.base.WheelItemView android:id="@+id/wheel_view_left" android:layout_width="160dp" android:layout_height="wrap_content" app:wheelItemVerticalSpace="12dp" app:wheelTotalOffsetX="12dp" /> <jsc.kit.wheel.base.WheelView android:id="@+id/wheel_view_left" android:layout_width="160dp" android:layout_height="wrap_content" app:wheelItemVerticalSpace="12dp" app:wheelTotalOffsetX="-12dp" />
ColumnWheelDialog
多列互不关联底部弹窗,最多支持5列。相应的列有数据则显示,无数据则不显示。
private ColumnWheelDialog showDialog() { ColumnWheelDialog<WheelItem, WheelItem, WheelItem, WheelItem, WheelItem> dialog = new ColumnWheelDialog<>(getActivity()); dialog.show(); dialog.setTitle("选择菜单"); dialog.setCancelButton("取消", null); dialog.setOKButton("确定", new ColumnWheelDialog.OnClickCallBack<WheelItem, WheelItem, WheelItem, WheelItem, WheelItem>() { @Override public boolean callBack(View v, @Nullable WheelItem item0, @Nullable WheelItem item1, @Nullable WheelItem item2, @Nullable WheelItem item3, @Nullable WheelItem item4) { return false; } }); dialog.setItems( initItems("菜单选项一"), initItems("菜单选项二"), initItems("菜单选项三"), initItems("菜单选项四"), initItems("菜单选项五") ); dialog.setSelected( new Random().nextInt(50), new Random().nextInt(50), new Random().nextInt(50), new Random().nextInt(50), new Random().nextInt(50) ); private WheelItem[] initItems(String label) { final WheelItem[] items = new WheelItem[50]; for (int i = 0; i < 50; i++) { items[i] = new WheelItem(label + (i < 10 ? "0" + i : "" + i)); } return items; }
DateTimeWheelDialog
日期时间选择底部弹窗,最多支持到分钟。
private DateTimeWheelDialog showDialog(int type) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2015); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); Date startDate = calendar.getTime(); calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2020); Date endDate = calendar.getTime(); DateTimeWheelDialog dialog = new DateTimeWheelDialog(getActivity()); dialog.show(); dialog.setTitle("选择时间"); int config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR_MINUTE; switch (type) { case 1://只显示年 config = DateTimeWheelDialog.SHOW_YEAR; break; case 2://显示年、月 config = DateTimeWheelDialog.SHOW_YEAR_MONTH; break; case 3://显示年、月、日 config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY; break; case 4://显示年、月、日、时 config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR; break; case 5://显示年、月、日、时、分 config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR_MINUTE; break; } dialog.configShowUI(config); dialog.setCancelButton("取消", null); dialog.setOKButton("确定", new DateTimeWheelDialog.OnClickCallBack() { @Override public boolean callBack(View v, @NonNull Date selectedDate) { tvResult.setText(SimpleDateFormat.getInstance().format(selectedDate)); return false; } }); dialog.setDateArea(startDate, endDate, true); dialog.updateSelectedDate(new Date()); }
作者:JustinRoom
链接:https://www.jianshu.com/p/cd29b6c9222e
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦