1 ImportAndroid.content.Context;2 ImportAndroid.graphics.Canvas;3 ImportAndroid.graphics.Color;4 ImportAndroid.graphics.Paint;5 ImportAndroid.util.AttributeSet;6 ImportAndroid.view.View;7 8 /**9 * Rotation of the blockTen * One * @authorDr A */ - Public classRotatingrectextendsView { - the PrivatePaint p;//Brush Objects - Private floatdegrees = 0; - - /**used by the resource resolver .*/ + PublicRotatingrect (context context, AttributeSet attrs,intdefstyleattr) { - Super(context, attrs, defstyleattr); + A initproperties (); at } - - PublicRotatingrect (Context context, AttributeSet attrs) { - Super(context, attrs); - - initproperties (); in } - to PublicRotatingrect (Context context) { + Super(context); - the initproperties (); * } $ Panax Notoginseng /**Initialize Properties*/ - Private voidInitProperties () { thep =NewPaint (); +P.setcolor (color.red);//Set Red A } the + @Override - Public voidDraw (canvas canvas) { $ Super. Draw (canvas); $ -Canvas.save ();//Save State - //canvas.rotate (degrees); //rotate around the upper left corner theCanvas.translate (200, 200);//adjust the position, in order to show the full. -Canvas.rotate (degrees, 50, 50);//rotates around the center point. Wuyi //0, 0, 100, 100 the value of the distance boundary. theCanvas.drawrect (0, 0, 100, 100, p); - Wudegrees++; -Canvas.restore ();//Recovery About $ //make it invalid. So when you redraw again, check to see if the view is in a valid state, - invalidate (); - } - A}
1 < Com.jikexueyuan.drawapi.RotatingRect 2 Android:layout_width = "Fill_parent" 3 android:layout_height= "fill_parent"/>
3. Use the drawing API to customize the view---rotated squares