1 year ago
#358772
Ali
How to draw line with corner radius box using canvas
I want to draw line of box with box corner radius.
Expected Output
But what i get
Code
@Override
protected void onDraw(Canvas canvas) {
if (bytes != null) {
int[] gradientColors = new int[]{
Color.parseColor("#B3F90403"),
Color.parseColor("#B3E7D104"),
Color.parseColor("#B317A300")
};
float[] gradientColorPos = new float[]{
0.33f, 0.66f, 0.99f
};
paint.setShader(new LinearGradient(0, 0, 0f, getHeight() / 2, gradientColors, gradientColorPos, Shader.TileMode.MIRROR));
float barWidth = getWidth() / density;
float div = bytes.length / density;
paint.setStrokeWidth(barWidth - gap);
for (int i = 0; i < density; i++) {
int count = 0;
int bytePosition = (int) Math.ceil(i * div);
int top = getHeight() + ((byte) (Math.abs(bytes[bytePosition]) + 128)) * getHeight() / 128;
int col = Math.abs((getHeight() - top));
for (int j = 0; j < col + 1; j += barWidth) {
float barX = (i * barWidth) + (barWidth / 2);
float y1 = getHeight() - ((barWidth + (gap / 2f)) * count);
float y2 = getHeight() - ((barWidth - gap / 2f) + ((barWidth + gap / 2f) * count));
canvas.drawLine(barX, y1, barX, y2, paint);
count++;
}
}
super.onDraw(canvas);
}
}
android
kotlin
canvas
paint
visualizer
0 Answers
Your Answer