Package game. test;
Import Android. App. activity;
Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. color;
Import Android. Graphics. paint;
Import Android. Graphics. rect;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. OS. message;
Import Android. View. view;
Import Android. View. window;
Import Android. View. windowmanager;
Public class gametest extends activity implements runnable {
/** Called when the activity is first created .*/
Myview;
Handler handler;
Boolean bexit = false;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
// Hide icons such as battery and all modifiers (status bar)
This. getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
Windowmanager. layoutparams. flag_fullscreen );
// Hide the title bar (program name)
This. requestwindowfeature (window. feature_no_title );
Myview = new myview (this );
Handler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
Myview. invalidate ();
}
};
Setcontentview (myview );
New thread (this). Start ();
}
@ Override
Public void run (){
While (! Bexit ){
Handler. sendemptymessage (0 );
Try {
Thread. Sleep (500 );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
}
}
Class myview extends view {
Private paint;
Private int left;
Public myview (context ){
Super (context );
Paint = new paint ();
Paint. setantialias (true); // set the paint brush to be non-sawtooth (if not set, the effect is poor)
This. setkeepscreenon (true); // set the background to always bright.
Paint. setcolor (color. Red );
Left = 0;
}
@ Override
Public void draw (canvas ){
Super. Draw (canvas );
Canvas. drawcolor (color. White); // you can specify the screen color.
Rect = new rect (left, 20, left + 10, 30); // The last two parameters here are not the width and height, but the coordinates at the bottom right corner of the rectangle.
Canvas. drawrect (rect, paint );
Left + = 10;
If (left> 200)
Left = 0;
}
}