对于android初学者,最烦的就是学习自定义控件。原生的控件不是丑就是无法满足需求,不得以我们只好自己重写控件的方法,下面我就为大家介绍一下某大神自定义的wheel控件Android滚轮控件,基于ListView实现,可以自定义样式。,此控件可以实现城市选择的多级联动,时间选择等多种功能,具体自己DIY呗!
效果图:
首先看一下布局main_layout
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.wx.wheelview.widget.WheelView
android:id="@+id/main_wheelview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"/>
<com.wx.wheelview.widget.WheelView
android:id="@+id/sub_wheelview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"/>
<com.wx.wheelview.widget.WheelView
android:id="@+id/child_wheelview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"/>
</LinearLayout>
接着看MainActivity
/**
* 联动WheelView
*/
private void initWheel1() {
mainWheelView = (WheelView) findViewById(R.id.main_wheelview);
mainWheelView.setWheelAdapter(new ArrayWheelAdapter(this)); //设置滚轮数据适配器s
mainWheelView.setSkin(WheelView.Skin.Holo); //设置背景颜色
mainWheelView.setWheelData(createMainDatas()); //设置滚轮数据