Image and animation in Android Development (I) painting and Canvas Learning

Source: Internet
Author: User

Paint class
* The Paint class is used to describe the color and style of the image, such as the width, color, transparency, and fill effect.
* When using the Paint class, you must first create an object of this class, which can be implemented through the constructor of this class. The general implementation code is:
* Paintpaint = newPaint ();
* After creating a Paint object, you can use the method provided by this object to change the default settings of the Paint brush.
Canvas
* The Canvas class represents the Canvas. You can use the constructor provided by this class to draw various images.
* Generally, to draw images in Android, you must first create a View that inherits the View class and override its onDraw method in this class,
* Add the view to the Activity that displays the drawing.

The xml file implementing this instance is defined as follows: Copy codeThe Code is as follows: <FrameLayoutxmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Tools: context = ". Draw_View"
>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello_world"/>
<Com. example. draw_view.DrawView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
</FrameLayout>

The source code is as follows:Copy codeThe Code is as follows: publicclassDrawViewextendsView {
PublicDrawView (Contextcontext, AttributeSetattrs ){
Super (context, attrs );
// TODOAuto-generatedconstructorstub
}
@ Override
ProtectedvoidonDraw (Canvascanvas ){
// TODOAuto-generatedmethodstub
Super. onDraw (canvas );
Paintpaint = newPaint ();
Paint. setColor (Color. RED );
Paint. setShadowLayer (180,180,180, 3, Color. rgb ));
Canvas. drawRect (40, 40, 200,100, paint );
}

}

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.