Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Airsaid/Android-PickerView-Library

Simple PickerView for Android - code from https://github.com/saiwu-bigkoo/Android-PickerView
https://github.com/Airsaid/Android-PickerView-Library

Last synced: about 1 month ago
JSON representation

Simple PickerView for Android - code from https://github.com/saiwu-bigkoo/Android-PickerView

Awesome Lists containing this project

README

        

# Android-PickerView-Library
~~这是一个高仿 IOS PickerView 控件的库:https://github.com/Airsaid/Android-PickerView-Library。在 https://github.com/saiwu-bigkoo/Android-PickerView 代码基础上进行封装、优化。由于原库作者不再维护,所以新开了该库。后期如有时间,将会对整体代码重构,核心采用自定义 LayouManager 实现。~~

原库已经有人接手更新,并且代码已经重构。推荐大家使用,地址:https://github.com/saiwu-bigkoo/Android-PickerView

**该库暂时停止维护,后续可能会进行重构(重构前建议大家不要使用)**

# 预览
![](https://github.com/Airsaid/Android-PickerView-Library/blob/master/gif/pickerview.gif)

# 使用
* 首先需要在 build.gradle 文件中添加依赖:
```
dependencies {
compile 'com.airsaid.library:pickerview:1.0.3'
}
```

添加好依赖后,重新同步工程。可根据需求使用如下选择器:

* 城市选择:
```
CityPickerView mCityPickerView = new CityPickerView(this);
// 设置点击外部是否消失
// mCityPickerView.setCancelable(true);
// 设置滚轮字体大小
// mCityPickerView.setTextSize(18f);
// 设置标题
// mCityPickerView.setTitle("我是标题");
// 设置取消文字
// mCityPickerView.setCancelText("我是取消文字");
// 设置取消文字颜色
// mCityPickerView.setCancelTextColor(Color.GRAY);
// 设置取消文字大小
// mCityPickerView.setCancelTextSize(14f);
// 设置确定文字
// mCityPickerView.setSubmitText("我是确定文字");
// 设置确定文字颜色
// mCityPickerView.setSubmitTextColor(Color.BLACK);
// 设置确定文字大小
// mCityPickerView.setSubmitTextSize(14f);
// 设置头部背景
// mCityPickerView.setHeadBackgroundColor(Color.RED);
mCityPickerView.setOnCitySelectListener(new OnSimpleCitySelectListener(){
@Override
public void onCitySelect(String prov, String city, String area) {
// 省、市、区 分开获取
Log.e(TAG, "省: " + prov + " 市: " + city + " 区: " + area);
}

@Override
public void onCitySelect(String str) {
// 一起获取
Toast.makeText(MainActivity.this, "选择了:" + str, Toast.LENGTH_SHORT).show();
}
});
mCityPickerView.show();
```
* 时间选择:
```
// TimePickerView 同样有上面设置样式的方法
TimePickerView mTimePickerView = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
// 设置是否循环
// mTimePickerView.setCyclic(true);
// 设置滚轮文字大小
// mTimePickerView.setTextSize(TimePickerView.TextSize.SMALL);
// 设置时间可选范围(结合 setTime 方法使用,必须在)
// Calendar calendar = Calendar.getInstance();
// mTimePickerView.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR));
// 设置选中时间
// mTimePickerView.setTime(new Date());
mTimePickerView.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
@Override
public void onTimeSelect(Date date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Toast.makeText(MainActivity.this, format.format(date), Toast.LENGTH_SHORT).show();
}
});
mTimePickerView.show();
```
* 选项选择:
```
OptionsPickerView mOptionsPickerView = new OptionsPickerView<>(this);
final ArrayList list = new ArrayList<>();
list.add("男");
list.add("女");
// 设置数据
mOptionsPickerView.setPicker(list);
// 设置选项单位
// mOptionsPickerView.setLabels("性");
mOptionsPickerView.setOnOptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int option1, int option2, int option3) {
String sex = list.get(option1);
Toast.makeText(MainActivity.this, sex, Toast.LENGTH_SHORT).show();
}
});
mOptionsPickerView.show();
```
# 更新日志
* 1.0.2:修复部分城市文字乱码bug,修复设置字体过小后分割线无法对齐bug。
* 1.0.1:修复内存泄露问题,修复设置setTime()方法后字体设置无效bug。

# 联系我
* 博 客:http://blog.csdn.net/airsaid
* QQ群:5707887

# 感谢
* https://github.com/saiwu-bigkoo/Android-PickerView