Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit of viewportWidth and viewportHeight in case VectorDrawable

I tried to find out what could be the unit(dp,sp,px) of viewportWidth and viewportHeight in case VectorDrawable, but I didn't get any where unit of viewportWidth and viewportHeight. Below is what I got from Android documentation.

https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html

  • android:width Used to define the intrinsic width of the drawable. This support all the dimension units, normally specified with dp.
  • android:height Used to define the intrinsic height the drawable. This support all the dimension units, normally specified with dp.
  • android:viewportWidth Used to define the width of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.
  • android:viewportHeight Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.

Can any one please help me.

like image 445
Anil Avatar asked Jan 31 '18 14:01

Anil


1 Answers

viewportWidth and viewportHeight don't have physical units associated with them. This is because there isn't a meaningful unit you can associate with them, as a vector drawable will always be scaled to a physical size. The vector drawable's units in SVG speak are in the "user coordinate system," which means that the drawable's units are whatever units you are using to set the drawable's actual size.

The width and height define the default size of the vector drawable. These have meaningful units because that is the size the drawable will appear if you don't otherwise specify a size.

For example, if you have a vector drawable with a size of 50x50 dp, and the viewport size is 50x50, the "units" of the viewport size can be interpreted as dp because each "unit" of the drawable maps to a single dp.

Similarly, if the size of that drawable is 50x50 px, the "units" of the viewport are effectively px- each "unit" of the drawable will be a single pixel.

like image 114
Bryan Herbst Avatar answered Oct 25 '22 05:10

Bryan Herbst