How to generate an image number of times in android -
i have image rotates on screen. problem is, want generate image again , again on screen, after 10 seconds. tried lot using loop. not working. want generate same rotating image again , again on screen. please help. in advance. here code.
@override public void ondraw(canvas canvas) { // todo auto-generated method stub super.ondraw(canvas); int draw_x = math.round(system.currenttimemillis() % (this.getwidth() * 2)); int draw_y = math.round(system.currenttimemillis() % (this.getheight() * 2)); (int = 0; < 10; i++) { if (draw_x > this.getwidth()) draw_x = (this.getwidth() * (2)) - draw_x; if (draw_y > this.getheight()) draw_y = (this.getheight() * (2)) - draw_y; if (draw_x > this.getwidth()) draw_x = (this.getwidth() * (2)) - draw_x; if (draw_y > this.getheight()) draw_y = (this.getheight() * (2)) - draw_y; canvas.drawbitmap(eball, draw_x, draw_y, null); image.add(eball); float time = system.currenttimemillis(); while ((time+50000)>system.currenttimemillis()); i++; invalidate(); } }
busy loop definitely bad idea. never that. should use android animation framework , rotate view or use handler()
, post delayed runnable
:
handler h = new handler(); .... protected runnable mtick = new runnable() { @override public void run() { methodthatrotatestheimage(); h.postdelayed( this, delayinmillis ); } }
and start do:
h.post( mtick );
and stop:
h.removecallbacks( mtick );
Comments
Post a Comment