'Java delay in a loop Canvas
Lines are drawn in a Canvas loop. I've tried a lot of doing the loop step by step with intervals, but nothing works. The presentation of the lines drawn in the loop is displayed at once without pauses.
This is my code in a Java class LineView:
public void onDraw(Canvas canvas) {
paint.setStrokeWidth(5);
for (i = 0; i < 25; i++) {
paint.setColor(Color.argb(255, 10 * i, 255 - (10 * i), 255 - (5 * i)));
canvas.drawLine(pointArrayStart[i].x, pointArrayStart[i].y, pointArrayEnd[i].x, pointArrayEnd[i].y, paint);
super.onDraw(canvas);
// ------------------------------ The next Tread doesn't work the way I want
try{
Thread.sleep(100);
}catch(InterruptedException ex){
//do nothing
}
}
}
Solution 1:[1]
Can you try calling Thread.sleep(100) before you call super.onDraw(canvas)? If that doesn't work and you don't get a satisfactory answer here can you reach out to the Android Discord?
Also, please add examples of what you've tried that didn't work, and a basic reproduction would be super helpful! Lastly, your question isn't phrased too clearly, maybe you could improve it before asking in the Discord? ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jens Meindertsma |
