Hello, there is a task; in Java, under Android, you need to write a task: create a snowman and make its constituent objects change color at different speeds. Color change should be implemented in the stream.
I managed to write code, but I donβt understand how exactly this animation should fit into this stream. Here is the actual code, written in Eclipse:
package ru.ucheba; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Style; import android.os.Bundle; import android.os.SystemClock; import android.view.View; public class Zadanie2 extends Activity { int a = 255; int r = 100; int g = 0; int b = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { public Panel(Context context) { super(context); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); Paint p1 = new Paint(); p1.setStyle(Style.FILL); p1.setARGB(a, r, g, b); canvas.drawCircle(270, 170, 70, p1); for (int i = 0; i < 5; i++) { r--; SystemClock.sleep(10); invalidate(); } for (int j = 0; j < 15; j++) { p1.setARGB(a, r, g, b); g--; canvas.drawCircle(270, 310, 100, p1); SystemClock.sleep(20); invalidate(); } for (int k = 0; k < 30; k++) { p1.setARGB(a, r, g, b); b--; canvas.drawCircle(270, 510, 150, p1); SystemClock.sleep(40); invalidate(); } } class Task extends Thread { @Override public void run() { } } } } Than to fill the run() method I understand, but I swear on either canvas , p1 , or invalidate() . I ask for help
p1andcanvas, you obviously have a limited scope for variables. It is worth getting acquainted with the transfer of values ββto the nested class in general and the new stream in particular. - pavlofff