3. Use the drawing API to customize the view---rotated squares

Source: Internet
Author: User

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

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.