-
Notifications
You must be signed in to change notification settings - Fork 26
Custom Effect
李涛 edited this page May 30, 2023
·
6 revisions
- Add an icon or text for the track starting and ending
niftySlider.apply {
effect = ITEffect(this).apply {
setStartIcon(R.drawable.icon_font) //the icon for track start position
setEndIcon(R.drawable.icon_font) //the icon for track end position
startText = "down" //the text for track start position
endText = "up" //the text for track end position
startIconSize = 10.dp //the icon size of the track start position
endIconSize = 14.dp //the icon size of the track end position
startTextSize = 12f.dp //the text size of the track start position
endTextSize = 12f.dp //the text size of the track end position
startTintList = ColorStateList.valueOf(iconTintColor) //the icon color of the track start position
endTintList = ColorStateList.valueOf(iconTintColor) //the icon color of the track end position
startPadding = 12.dp //the start padding of the icon or text
endPadding = 12.dp //the end padding of the icon or text
}
val colorEffect = ColorPickEffect(niftySlider).apply {
//Registers a callback to be invoked when the slider changes(callback color inter value)
colorValueChangeListener = ColorPickEffect.OnColorValueChangeListener { slider, color, fromUser ->
}
//update gradient colors
updateColors(
intArrayOf(
Color.WHITE,
Color.BLUE,
Color.BLACK
)
)
}
- Add animation to the sliders
val animEffect = AnimationEffect(niftySlider).apply {
animDuration = 500L //animation duration
endAnimDelay = 1000L //end animation delay
srcTrackHeight = 3.dp //source track height
srcThumbHeight = 6.dp //source thumb height
srcThumbWidth = 6.dp //source thumb width
srcThumbRadius = 3.dp //source thumb radius
srcThumbColor = thumbColor //source thumb color
srcTrackColor = thumbTrackColor //source track color
srcInactiveTrackColor = thumbInactiveColor //source inactive track color
targetTrackHeight = 12.dp //target track height
targetThumbHeight = 16.dp //target thumb height
targetThumbWidth = 8.dp //target thumb width
targetThumbRadius = 5.dp //target thumb radius
targetThumbColor = Color.WHITE //target thumb color
targetTrackColor = ColorUtils.setAlphaComponent(Color.WHITE, 0xDD) //target track color
targetInactiveTrackColor = ColorUtils.setAlphaComponent(Color.WHITE, 0x33) //target inactive track color
//Sets the interpolator of this animation effect
setInterpolator(FastOutLinearInInterpolator())
animationListener = object : AnimationEffect.OnAnimationChangeListener {
override fun onEnd(slider: NiftySlider) {
//do something on animation end
}
}
}
- Add graph to the sliders
val chartEffect = ChartEffect(niftySlider).apply {
chartColor = Color.parseColor("#33FFFFFF") //graph color
chartMaxHeight = 28f.dp //graph max height
//update graph key points, point x corresponds to the slider progress ,point y is popularity value and will be automatically converted.
updateKeyPoint(mutableListOf(
PointF(0f,10f),
PointF(5f,50f),
PointF(10f,70f),
PointF(90f,10f),
PointF(95f,180f),
PointF(100f,10f),
))
}