View animation instance

Source: Internet
Author: User
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;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.