<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.zuluft.lib.ExplosionView
android:id="@+id/explosionView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
explosionView.start()
}
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add dependency to app gradle:
implementation 'com.github.Zuluft:ExplosionView:VERSION_TAG
Item icon drawable.
Default value: ❤️
Original width of the item.
Default value: 40dp
.
Original height of the item.
Default value: 0dp
.
If either
itemWidth
oritemHeight
is 0dp, item size will be computed using drawable's aspect ratio.
Move factor controls single item moving behaviour.
As much as move factor value is near to 0, item behaviour becomes more chaosic.
As much as move factor is greater then 0, item behaviour becomes more ordered.
Move factor values for the items are distributed randomly between minMoveFactor
and maxMoveFactor
.
Minimal move factor value.
Default value: 0.7
Maximal move factor value.
Default value: 0.8
Animation duration controls how much time should take one item's moving scene.
Animation duration values for the items are distributed randomly between minAnimDuration
and maxAnimDuration
.
Minimal animation duration value.
Default value: 1000
Maximal animation duration value.
Default value: 10000
Animation delay controls how much time should be delayed item's moving scene.
Animation delay values for the items are distributed randomly between minAnimDelay
and maxAnimDelay
.
Minimal animation delay value.
Default value: 1000
Maximal animation delay value.
Default value: 10000
Scale controls how much should be resized item's original size.
Scale values for the items are distributed randomly between minScale
and maxScale
.
Minmal scale value.
Default value: 0.7
Maximal scale value.
Defaul value: 1.1
Alpha controls opacity of the item.
Alpha values for the items are distributed randomly between minAlpha
and maxAlpha
.
Minimal alpha value.
Default value: 0.5
Maximal alpha value.
Default value: 1
When dragging is enabled, you can catch moving item and drag it. When you release it, it'll continue it's moving scene.
Enables or disables dragging mode.
Default value: false
Spred direction controls where to start and where to finish every single item's moving scene.
Possible values: TOP
, BOTTOM
Default value: TOP
There are 2 spread modes available.
In unidirectional mode, all items moving scenes are started from top or from bottom of the view.(It's depended on spreadDirection
property)
In Bidirectional mode, half of items moving scenes are started from one site and another half's moving scenes-from another site.
Possible values: UNIDIRECTIONAL
, BIDIRECTIONAL
Default value: UNIDIRECTIONAL
Horizontal offset controls the range of randomly generated X
coordinates of item's path, during animation scene.
For example, if horizontal offset is 20
pixels, randomly generated X
coordinates will be in [20, view.width-20]
range
Horizontal offset value.
Default value: 1dp
Repeat count controls, how many times should animation scene of every single item be repeated.
Repeat count value.
Default value: -1
When repeat count is
-1
, it means that animation should be repeated infinitely.
<com.zuluft.lib.ExplosionView
android:id="@+id/explosionView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemWidth="50dp"
app:itemHeight="30dp"
app:ItemsCount="100"
app:minMoveFactor="0.2"
app:maxMoveFactor="1.1"
app:minAnimDuration="400"
app:maxAnimDuration="15000"
app:minAnimDelay="1000"
app:maxAnimDelay="7000"
app:minScale="0.5"
app:maxScale="1.5"
app:minAlpha="0.3"
app:maxAlpha="1"
app:isDraggable="true"
app:horizontalOffset="20dp"
app:spreadDirection="BOTTOM"
app:spreadMode="UNIDIRECTIONAL"
app:repeatCount="5"
/>
ExplosionView(
ExplosionViewSettings
.Builder(context!!)
.itemWidth(50)
.itemHeight(30)
.itemCount(100)
.minMoveFactor(0.5f)
.maxMoveFactor(1.1f)
.minAnimDuration(400L)
.maxAnimDuration(15000L)
.minScale(0.5f)
.maxScale(1.5f)
.minAlpha(0.3f)
.maxAlpha(1f)
.isDraggable(true)
.horizontalOffset(20)
.spreadDirection(Bottom)
.spreadMode(Unidirectional)
.repeatCount(5)
.build()
)
Starts all item's animation scenes.
Immediately stops all item's animation scenes.
Waits until current animation scenes are finished and then stops all of them.
Return type: Boolean
Returns true
, if animations are running. Othervise - false
.
Return type: ExplosionViewSettings
Returns current settings of ExplosionView
Changes settings of ExplosionView
Example:
explosionView.changeSettings(
explosionView.getSettings()
.newBuilder()
.isDraggable(true)
.spreadMode(Bidirectional)
.minAlpha(0.5f)
.maxMoveFactor(1.5f)
.build()
)