【开源】WheelView
WheelView
- https://github.com/LukeDeighton/WheelView
介绍:
一个转盘效果控件,转盘中的数据加载和ListView类似,是用过的adapter方式。可以设置一个角度来决定什么位置的item被选中。运行效果:

使用说明:
WheelView is an Android library that allows drawables to be placed on a rotatable wheel. It behaves like a Circular ListView where items rotate rather than scroll vertically. It isn't limited by the number of items that can fit on the wheel since it will cycle through each adapter position when the wheel is rotated. It can be rotated at any angle and from any position.
The WheelView can be used as a way to select one item from a list. The SelectionAngle determines what position on the wheel is selected. You can also receive a callback for when an item is clicked, and whether it is selected. Have a look at the sample for a working example!
The library is still in its infancy so if there are any bugs or missing features please let me know!
首先添加进xml:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.lukedeighton.wheelview.WheelView android:id="@+id/wheelview" android:layout_width="match_parent" android:layout_height="match_parent" app:wheelColor="@color/grey_400" app:rotatableWheelDrawable="false" app:selectionAngle="90.0" app:wheelPosition="bottom" app:wheelOffsetY="60dp" app:repeatItems="true" app:wheelRadius="276dp" app:wheelItemCount="14" app:wheelPadding="13dp" app:wheelItemRadius="43dp"/></RelativeLayout> |
设置adapter:
|
1
2
3
4
5
6
7
8
9
10
|
wheelView.setAdapter(new WheelAdapter() { @Override public Drawable getDrawable(int position) { //return drawable here - the position can be seen in the gifs above } @Override public int getCount() { //return the count }}); |
监听函数:
(1)监听选中事件:
|
1
2
3
4
5
6
|
wheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectListener() { @Override public void onWheelItemSelected(WheelView parent, int position) { //the adapter position that is closest to the selection angle }}); |
(2)监听点击item事件:
|
1
2
3
4
5
6
|
wheelView.setOnWheelItemClickListener(new WheelView.OnWheelItemClickListener() { @Override public void onWheelItemClick(WheelView parent, int position, boolean isSelected) { //the position in the adapter and whether it is closest to the selection angle }}); |
(3)监听旋转角度变化事件:
|
1
2
3
4
5
6
|
wheelView.setOnWheelAngleChangeListener(new WheelView.OnWheelAngleChangeListener() { @Override public void onWheelAngleChange(float angle) { //the new angle of the wheel }}); |
posted on 2015-03-30 11:16 wasdchenhao 阅读(457) 评论(0) 收藏 举报
浙公网安备 33010602011771号