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