See below for code block, I have a view object which is supposed to get the values of the grids size then draw a rectangle and colour it blue, then draw circles at certain points in the rectangle, while it does draw as so, it doesnt fill up the view object’s size I have created which covers the whole screen, instead it stops when the circle quota has been met, I want it to fill the view object with the rectangle and circles
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
recalculateDimensions(w, h)
}
private fun recalculateDimensions(w: Int, h: Int) {
val diameterX = w / (colCount + (colCount + 1) * circleSpacingRatio)
val diameterY = h / (rowCount + (rowCount + 1) * circleSpacingRatio)
circleDiameter = minOf(diameterX, diameterY)
circleSpacing = circleDiameter * circleSpacingRatio
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val gridLeft = 0f
val gridTop = 0f
val gridRight: Float = gridLeft + colCount * (circleDiameter+circleSpacing) + circleSpacing
val gridBottom: Float = gridTop + rowCount * (circleDiameter+circleSpacing) + circleSpacing
canvas.drawRect(gridLeft, gridTop, gridRight, gridBottom, gridPaint)
val radius = circleDiameter/2f
for (row in 0 until rowCount) {
// The vertical center is the same for each circle in the row
val cy = gridTop + circleSpacing + ((circleDiameter + circleSpacing) * row) + radius
for (col in 0 until colCount) {
// We will later on want to use the game data to determine this
val paint = noPlayerPaint
// Drawing circles uses the center and radius
val cx = gridLeft + circleSpacing + ((circleDiameter + circleSpacing) * col) + radius
canvas.drawCircle(cx, cy, radius, paint)
}
}
}
I’ve tried a bunch of ai solutions lol, also tried removing circle spacing values but it just removed the extra padding of colour after a circle was drawn on the end.
Faraan Abrahamy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.