The effect is as follows:
The subject code is as follows:
Package com. free. chart;
Import android. content. Context;
Import android. graphics. Canvas;
Import android. graphics. Color;
Import android. graphics. Paint;
Import android. view. SurfaceHolder;
Import android. view. SurfaceView;
Public class DrawTextStudy extends SurfaceView implements SurfaceHolder. Callback {
SurfaceHolder holder;
Public DrawTextStudy (Context context ){
Super (context );
// TODO Auto-generated constructor stub
Holder = this. getHolder ();
Holder. addCallback (this );
}
@ Override
Public void surfaceChanged (SurfaceHolder holder, int format, int width,
Int height ){
// TODO Auto-generated method stub
}
@ Override
Public void surfaceCreated (SurfaceHolder holder ){
// TODO Auto-generated method stub
New Thread (new MyThread (). start ();
}
@ Override
Public void surfaceDestroyed (SurfaceHolder holder ){
// TODO Auto-generated method stub
}
Void drawText (Canvas canvas, String text, float x, float y, Paint paint, float angle ){
If (angle! = 0 ){
Canvas. rotate (angle, x, y );
}
Canvas. drawText (text, x, y, paint );
If (angle! = 0 ){
Canvas. rotate (-angle, x, y );
}
}
Class MyThread implements Runnable {
@ Override
Public void run (){
// TODO Auto-generated method stub
Canvas canvas = null;
Try {
Canvas = holder. lockCanvas ();
Paint paint = new Paint ();
Paint. setColor (Color. WHITE );
Paint. setTextSize (20 );
Canvas. drawLine (100,100,100,400, paint );
DrawText (canvas, "Hello", 80,200, paint,-90 );
Paint. setColor (Color. RED );
Paint. setTextSize (40 );
DrawText (canvas, "free", 150,180, paint,-45 );
Paint. setColor (Color. BLUE );
DrawText (canvas, "World", 150, 80, paint, 0 );
Canvas. drawLine (100,100,400,100, paint );
} Catch (Exception e ){
} Finally {
Holder. unlockCanvasAndPost (canvas );
}
}
}
}
Activity call
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (new DrawTextStudy (this ));
}
From freeliver54