Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android XML| Understanding the pathData syntax

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:

  1. Circle.
  2. Oval.
  3. Empty Circle/Oval (putting it on another shape will cause this part to be transparent).

with explanation to what each pathData attribute does?

Thanks!

like image 514
user12597562891 Avatar asked Sep 10 '16 07:09

user12597562891


1 Answers

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".

like image 56
Jon Goodwin Avatar answered Sep 27 '22 20:09

Jon Goodwin