So i am trying to understand the pathData syntax in order to create some vector drawables via xml...
I am able to create any square shapes, but i just can't understand how to create circular shapes (such as oval or a circle).
could anyone give some examples of circular shapes:
with explanation to what each pathData attribute does?
Thanks!
Notes on Paths (SVG notation used in anroid-vectordrawable) : Paths have a compact coding. For example M (for 'move to') precedes initial numeric x and y coordinates and L (line to) precedes a point to which a line should be drawn. Further command letters (C, S, Q, T and A) precede data that is used to draw various Bézier and elliptical curves. Q is quadratic Bézier, Z is used to close a path. In all cases, absolute coordinates follow capital letter commands and relative coordinates are used after the equivalent lower-case letters.
SVG path notation.
Command :A (absolute)a (relative)
Name :elliptical arc
Parameters :(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+
Description:Draws an elliptical arc from the current point to
(x, y). The size and
orientation of the ellipse are defined by two radii
(rx, ry) and an
x-axis-rotation, which indicates how the
ellipse as a whole is rotated relative to the current
coordinate system. The center (cx,
cy) of the ellipse is calculated
automatically to satisfy the constraints imposed by the
other parameters. large-arc-flag and
sweep-flag contribute to the automatic
calculations and help determine how the arc is drawn.
Use this (circle.xml
), in your res/drawable
folder:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportHeight="64"
android:viewportWidth="64">
<path
android:fillColor="#ff0000"
android:pathData="M22,32
A10,10 0 1,1 42,32
A10,10 0 1,1 22,32 Z" />
</vector>
Parameters :(rx, ry x-axis-rotation large-arc-flag, sweep-flag x, y )
(10, 10 0 1, 1 42, 32 )
(10, 10 0 1, 1 22, 32 )
NOTE:Superfluous white space and separators such as commas can be eliminated.
Two arc's make a circle.
Circle is a special case of oval, android:fillColor="@color/transparent".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With