PowerWheelPicker is a highly customizable wheel picker view for Android, backed by RecyclerView and SimpleCarousel.
To download this library, add dependency to your project.
dependencies {
implementation("com.cheonjaeung.powerwheelpicker.android:powerwheelpicker:<version>")
}
Add WheelPicker
view to your layout.
<com.cheonjaeung.powerwheelpicker.android.WheelPicker
android:id="@+id/wheelPicker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
All supported attributes:
Attribute | Type | Description |
---|---|---|
android:orientation | enum(horizontal, vertical) | Sets orientation of the WheelPicker . |
app:circular | boolean | If true , enable circular mode. |
app:selectorWidth | dimension | Size of the selector area. |
app:selectorHeight | dimension | Size of the selector area. |
WheelPicker
needs RecyclerView.Adapter
to handle data set. Create and add an adapter to WheelPicker
.
val wheelPicker = findViewById<WheelPicker>(R.id.wheelPicker)
wheelPicker.adapter = SampleAdapter()
class SampleAdapter : RecyclerView.Adapter<SampleAdapter.Holder>() {
// ...
}
WheelPicker
supports listeners for scrolling and item selected event.
There are 2 listeners, WheelPicker.OnScrollListener
and WheelPicker.OnItemSelectedListener
.
Both listeners can be added and removed via add
or remove
prefixed methods.
OnScrollListener
is a listener to receive scrolling event.
It is same to RecyclerView.OnScrollListener
.
wheelPicker.addOnScrollListener(object : WheelPicker.OnScrollListener() {
override fun onScrollStateChanged(wheelPicker: WheelPicker, @ScrollState newState: Int) {
// Action for scroll state changing.
}
override fun onScrolled(wheelPicker: WheelPicker, dx: Int, dy: Int) {
// Action for scrolling.
}
})
OnItemSelectedListener
is a listener to receive item selected event.
wheelPicker.addOnItemSelectedListener { _, position ->
Snackbar.make(findViewById(R.id.main), "Selected position: $position", 1000).show()
}
WheelPicker
has WheelPicker.ItemEffector
to support visual effects like transformation, alpha and others.
ItemEffector
has 3 callbacks, applyEffectOnScrollStateChanged
, applyEffectOnScrolled
and applyEffectOnItemSelected
.
It makes more flexible to apply visual effect.
wheelPicker.addItemEffector(object : WheelPicker.ItemEffector() {
// Implementation of custom effector.
})
This project has sample application in the sample directory. The sample app provides example of basic usage and visual effects.
Please see changelog file.
Copyright 2023 Cheon Jaeung.
This project is licensed under the Apache License Version 2.0. See License file for more details.