PickerView是什么
仿iOS的PickerView控件,带有3D圆弧效果,并封装了时间选择和选项选择这两种选择器。
WheelView —— 基础控件
带有3D圆弧效果。
支持文字、颜色、大小设置。
支持背景颜色设置。
支持item的分隔线设置。
支持item间距设置。
支持设置是否循环。
OptionsPickerView —— 选项选择器
支持一、二、三级联动数据。
支持一、二、三级不联动数据。
支持自定义布局。
支持自定义标题栏。
支持“省,市,区”等选项的单位(label)显示、隐藏和自定义。
支持dialog 模式显示。
支持自定义设置容器。
支持实时回调监听。
联动数据支持切换Item时,还原为第一项。
TimePickerView —— 时间选择器
支持选择年、月、日的范围。
支持年月日时分秒显示。
支持设置当前默认时间。
支持自定义布局。
支持自定义标题栏。
支持“年,月,日,时,分,秒”等选项的单位(label)显示、隐藏和自定义。
支持dialog 模式显示。
支持自定义设置容器。
支持实时回调监听。
使用方式
1.WheelView的使用
依赖
compile 'com.contrarywind:Android-PickerView:4.1.9'
layout中配置
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.contrarywind.view.WheelView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wheel"/>
</LinearLayout>
代码
package com.example.day011;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private WheelView wheel;
private ArrayWheelAdapter wheelAdapter;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
final List<String> list=new ArrayList<>();
list.add("我的中国心");
list.add("北国之春");
list.add("鹿港小镇");
wheel.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(int index) {
Log.i(TAG, "onItemSelected: "+list.get(index));
}
}