PickerView和AutoSize
PickerView是什么
仿iOS的PickerView控件,带有3D圆弧效果,并封装了时间选择和选项选择这两种选择器。
导包
implementation 'com.contrarywind:Android-PickerView:4.1.8'//PickerView
用法:
xml中的布局
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.contrarywind.view.WheelView
android:id="@+id/whee"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.contrarywind.view.WheelView>
</LinearLayout>
在代码中使用
package com.example.day11;
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 whee;
@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("刘禹臣是我");
list.add("刘禹臣是我儿");
whee.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(int index) {
Log.e("---",list.get(index));
}
});
ArrayWheelAdapter arrayWheelAdapter = new ArrayWheelAdapter(list);
whee.setAdapter(arrayWheelAdapter);
}
private void initView() {
whee = (WheelView) findViewById(R.id.whee);
}
}
效果图
联级选择器
final List<String> list=new ArrayList<>();
list.add("射雕英雄传");
list.add("神雕侠侣");
list.add("喜羊羊与灰太狼");
final List<String> list1=new ArrayList<>();
list1.add("郭靖");
list1.add("黄蓉");
list1.add("欧克瑟");
final List<String> list2=new ArrayList<>();
list2.add("杨过");
list2.add("小龙女");
list2.add("大雕");
final List<String> list3 = new ArrayList<>();
list3.add("喜洋洋");
list3.add("懒洋洋");
list3.add("慢洋洋");
final List<List<String>> listList=