Refreshing simple images and views for Android

Source: Internet
Author: User

Create View:

Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. color;
Import Android. Graphics. paint;
Import Android. Graphics. rect;
Import Android. Graphics. rectf;
Import Android. View. view;

Public class myview extends view {

Private paint;
 
Public myview (context ){
Super (context );
// Todo auto-generated constructor stub

Paint = new paint ();
// Set the paint brush to be non-sawtooth (if not set, the effect will be poor)
Paint. setantialias (true );
// Set the background to always bright
This. setkeepscreenon (true );
// Set the paint brush color
Paint. setcolor (color. Red );
}

@ Override
Protected void ondraw (canvas ){
// Todo auto-generated method stub
Super. ondraw (canvas );

// Set the screen color
Canvas. drawcolor (color. White );
// The first two parameters mean the coordinates in the upper left corner of the rectangle.
// The last two parameters mean the coordinates at the bottom right corner of the rectangle.
Rect = new rect (30, 30, 50, 50 );
// Draw a rectangle
Canvas. drawrect (rect, paint );
// Rectf is only in the float format of a rectangle, but it is different from the rect precision.
Rectf = new rectf (70f, 30f, 90f, 90f );
// Draw an ellipse
Canvas. drawarc (rectf, 0,360, true, paint );
// Draw a circle. The third parameter is the radius.
Canvas. drawcircle (150, 30, 20, paint );
Float [] points = new float [] {200f, 10f, 200f, 40f, 300f, 30f, 400f, 70f };
Canvas. drawlines (points, paint );
// Select two points in the array of specific points to draw a straight line
// Canvas. drawlines (points, 1, 4, paint );
Canvas. drawtext ("Hello World", 230, 30, paint );
}
}

 

Use View:

 

Import Android. App. activity;
Import Android. Graphics. color;
Import Android. Graphics. paint;
Import Android. OS. Bundle;
Import com. Main. myview;

Public class simplegraph extends activity {
 
Private Boolean iisstart = true;
Private myview;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );

Myview = new myview (this );

Setcontentview (myview );

// Refresh the view
New thread (New runnable (){

@ Override
Public void run (){
// Todo auto-generated method stub
While (iisstart)
{
Try {
Thread. Sleep (1000 );
} Catch (interruptedexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();

System. Out. println (E. tostring ());
}

// Use postinvalidate to directly update the interface in the thread

Myview. postinvalidate ();
}
}
}). Start ();
}
}

 

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.