Spin the Wheel is a highly customizable and interactive wheel view designed for Android applications. It allows developers to seamlessly integrate a spinning wheel feature into their apps, perfect for creating engaging experiences like games, raffles, decision-making tools, and more.
Key Features | |
---|---|
Customizable Design | Easily adjust colors, segments, text, and more to fit your app's theme. |
Smooth Animations | Provides a realistic spinning effect with customizable duration and easing. |
Flexible Integration | Simple setup with minimal configuration to get started quickly. |
Callback Support | Listen for spin results and perform actions based on user interactions. |
Whether you're building a game of chance, a prize wheel, or a fun decision-making app, Spin the Wheel brings creativity and engagement to your Android projects.
-
Add Jitpack to your project-level
settings.gradle.kts
:dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { ... maven { url = uri("https://jitpack.io") } } }
-
Add the library dependency to your module-level
build.gradle.kts
:dependencies { implementation("com.github.VuNgN:SpinTheWheel:latest-version") }
-
Add Jitpack to your project-level
settings.gradle
:dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { mavenCentral() maven { url 'https://jitpack.io' } } }
-
Add the library dependency to your module-level
build.gradle
:dependencies { implementation 'com.github.VuNgN:SpinTheWheel:latest-version' }
-
Add Jitpack to your
pom.xml
:<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
-
Add the library dependency:
<dependency> <groupId>com.github.VuNgN</groupId> <artifactId>SpinTheWheel</artifactId> <version>latest-version</version> </dependency>
In the layout:
<com.vungn.luckywheel.LuckyWheel
android:id="@+id/lwv"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@drawable/ig_edge_1"
app:arrow_height="50dp"
app:arrow_width="50dp"
app:arrow_image="@drawable/ig_arrow_1"
app:shadow_src="@drawable/ig_shadow_1"
app:border_color="#33FFFFFF"
app:border_width="30dp"
app:font_family="@font/roboto_bold"
app:text_padding="10dp" />
In code:
val lw = binding.lwv;
val wheelItems: List<WheelItem> = emptyList()
// add items to the wheel view
lw.addWheelItems(wheelItems)
// listen for the finish event
lw.setLuckyWheelReachTheTarget { item: WheelItem ->
// TODO: when the target item is reached
}
// listen for action events
lw.setListener(object : WheelListener {
override fun onSlideTheWheel() {
// TODO: when the wheel is swiped
}
override fun onTouchTheSpin() {
// TODO: when pressing the wheel arrow
}
})
// get random target
val randomNum = WheelUtils.getRandomIndex(wheelItems)
// start spinning the wheel
lw.rotateWheelTo(randomNum)
Note: I recommend using the
WheelUtils.getRandomIndex(wheelItems)
method to get random number for the target. If not, you need to calculate the total number of slices including the total probability of each slice. To get the total probability, use theWheelUtils.calculateTotalProbability(wheelItems)
method.
Method | Input | Description |
---|---|---|
addWheelItems() |
List<WheelItem> |
Add items to the wheel view. |
setLuckyWheelReachTheTarget() |
OnLuckyWheelReachTheTargeto |
Listen for the finish event when the target item is reached. |
setListener() |
WheelListener |
Listen for action events like sliding the wheel or touching the spin button. |
rotateWheelTo() |
Int |
Start spinning the wheel to the target index. |
resetWheel() |
None |
Reset the wheel to the initial state. |
setSliceRepeat() |
Int |
Set the number of times to repeat slices alternately |
setSpinTime() |
Int : time in millisecondSpinTime : default values |
Set the duration of the spinning animation. |
setWheelBorder() |
Int |
Set the border color. |
setWheelPadding() |
Int |
Set the border width. |
setWheelShadow() |
Int : resource of imageBitmap : bitmap of image |
Set the shadow image. |
setArrowImage() |
Int : resource of imageBitmap : bitmap of imageDrawable : drawable of image |
Set the arrow image. |
setArrowWidth() |
Int |
Set the width of the arrow. |
setArrowHeight() |
Int |
Set the height of the arrow. |
setArrowSize() |
(Int , Int ): width, height |
Set the size of the arrow. |
setTextPadding() |
Int |
Set the padding between text and edge for all slices. |
setTextSize() |
Float |
Set text size for all slices. |
setFontFamily() |
Int : resource of font |
Set the font family for all slices. |
val item = WheelItem(
text = "Item 1",
textColor = Color.WHITE,
backgroundColor = Color.RED,
probability = 1
)
Property | Type | Description |
---|---|---|
text |
String |
Text to display on the slice. |
textColor |
Int |
Color of the text. |
backgroundColor |
Int |
Background color of the slice. |
probability |
Int |
Probability of selected slice over total slices. |
- Border
- Arrow
- Shadow
- Slice
- Text
Support it by joining stargazers for this repository. ⭐
And follow me for my next creations! 🤩
Copyright 2024 VuNgN (Nguyễn Ngọc Vũ)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.