There is:

ImageView ivPct; Bitmap bitmap; Paint p; Canvas canvas; ivPct= (ImageView) findViewById(R.id.iv_pct); bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); p = new Paint(Paint.ANTI_ALIAS_FLAG); 

Further in the cycle, the color of the bitmap will change, but it must be done so the color changes with a period of a second.

 int[] clr = new int[] {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA}; for (int i = 0; i < clr.length; i++) { p.setColor(clr[i]); canvas.drawCircle(100, 100, 50, p); ivL.setImageBitmap(bitmap); ....... } 
  • I don’t know anything about androids, but Thread.sleep(1000); probably also works Thread.sleep(1000); ? Is the standard Java API available in full? - m. vokhm
  • in order to apply Thread.sleep (1000); Probably you need to somehow allocate a task to the stream and pause the stream I'll try. I just wanted to make it easier somehow. - kaaa
  • No, nothing is needed. Only enclose it in a try -- catch : try { Thread.sleep(1000); } catch (Exception x) {} try { Thread.sleep(1000); } catch (Exception x) {} . And it's easier for me to imagine where it is even easier :) - m. vokhm
  • If there are no other threads that can affect this, then sleep() will not cause exceptions, so an empty catch valid here. With a normal java machine, at least. About Android, I would separately clarify this point. - m. vokhm
  • one
    There are two features in Android: the main thread cannot be put to sleep and the UI can be changed from the background thread all the more. You need either Handler or View.postDelayed() - woesss

1 answer 1

Especially not edited. Pasted from my code.


  Runnable runnable = new Runnable() { public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { } h.sendEmptyMessage(); } }; Thread thread = new Thread(runnable); thread.start(); 

  final Handler h = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { //Перерисовка Bitmap return true; } }); 
  • Thank you very much! An example works great! - kaaa
  • And how to stop the flow now? Tried thread.stop (); but then the application crashes. - kaaa
  • I did not stop this stream. Perhaps his scavenger himself then removes. But I'm not so sure. - sapeg