WORK IN PROGRESS
Make canvas easier to use in Kotlin 😊
//create your shapes
val background = rectShape { view ->
color = Color.parseColor("#6fbf73")
cornerRadius = 16.dpToPx(context)
left = 100f
width = view.width / 2f
top = 100f
height = view.height / 3f
}
//create an animator
val canvasAnimator = obtainCanvasAnimator()
fun animate(){
canvasAnimator
.play(background.animate().right.to(this.width.toFloat()))
.start()
}
//draw them
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.draw(background)
}
Shapes | link |
---|---|
Rect | |
Circle | |
Text | |
Arc | |
Line | |
Triangle | |
Drawable | |
Path |
Follow the example of SwitchView
Shape animations are executed by an instance of ShapeAnimator
attached to your view
val canvasAnimator = CanvasAnimator(this)
All animated methods of shapes are wrapped into the method .animate()
For example, for a CircleShape
, you can animate his position (centerX) using
myCircleShape.animate().centerX.to(15);
Then use your ShapeAnimator
to execute this animation
shapeAnimator.play(myCircleShape.animate().centerX.to(15);)
.setDuration(500)
.start()
drawArc(centerX, centerY, circleRadius, startAngle, sweepAngle, paint)
drawArc(center: PointF, circleRadius, startAngle, sweepAngle, paint)
drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)
drawOval(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)
drawLine(start: PointF, end: PointF, paint)
drawRoundRect(left, top, right, bottom, rx, ry, paint)
addRoundRect(left, top, right, bottom, rx, ry, dir: Path.Direction)
addRoundRect(left, top, right, bottom, radiiArray, dir: Path.Direction)
arcTo(centerX, centerY, circleRadius, startAngle, sweepAngle, forceMoveTo)
arcTo(center: PointF, circleRadius, startAngle, sweepAngle, forceMoveTo)
arcTo(left, top, right, bottom, startAngle, sweepAngle, forceMoveTo)
Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/