Android ApiDemos example (65): Graphics-& gt; Drawable-& gt; S

Source: Internet
Author: User

In addition to using the Shape Drawable resource in XML (for example above), you can also use Code to define the Shape Drawable, which is a hierarchical graph of the Shape class defined in Android:

 

If you are familiar with 2D graph development, Path, Arc, Rect, Oval, and RoundRect, you should be familiar with them. In this example, ShapeDrawable uses code to create various ShapeDrawable and customize a Shape: MyShapeDrawable.

The Shader in Android is similar to that in other platforms (it can be painted by a monochrome Brush, a linear gradient Paint Brush, or a bitmap paint Brush ).

There are several examples of ShapeDrawable, and only the fourth RoundRect is a little strange. This is because PathEffect is used to draw the RoundRectShape Paint:

[Java]
PathEffect pe = new DiscretePathEffect (10, 4 );
PathEffect pe2 = new CornerPathEffect (4 );
MDrawables [3]. getPaint (). setPathEffect (
New ComposePathEffect (pe2, pe ));

PathEffect pe = new DiscretePathEffect (10, 4 );
PathEffect pe2 = new CornerPathEffect (4 );
MDrawables [3]. getPaint (). setPathEffect (
New ComposePathEffect (pe2, pe ));
 

PathEffect can affect the geometric shape of painting. Android provides several types of PathEffect, such as ComposePathEffect, ConerPathEffect, DashPathEffec, DiscretePathEffect, PathDashPathEffect, and SumPathEffect. Here, DiscretePathEffect can randomly offset the original path to achieve the effect of this example.

 
Author: mapdigit
 
 


 

Related Article

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.