Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the impact of viewportwidth/height on Android drawables

I have an vector drawable I imported from an SVG asset. Sometimes, I have to adjust the size. Usually I update width and height. What I can't work out is how viewportwidth and height also impact the svg. It seems changing these dimensions can push the svg out of view within the visible area.

What do these units of measurement represent ? What is it's relationship with width and height respectively ? The documentation from Google is, (as usual), woefully inadequate. Could someone please elaborate ?

like image 930
angryITguy Avatar asked Dec 28 '16 00:12

angryITguy


People also ask

What is viewportWidth in Android?

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.

What is viewport width and height android?

Most web browsers on Android (including Chrome) set the viewport to a large size by default (known as "wide viewport mode" at about 980px wide). Many browsers also zoom out as far as possible, by default, to show the full viewport width (known as "overview mode").

What are vector Drawables in Android?

A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.


Video Answer


2 Answers

The viewportWidth and viewPortHeight define the area of the document that the content of the VectorDrawable is drawn within. They are equivalent to the width and height fields of an SVG viewBox. Research how an SVG viewBox works if you need further explanation.

So imagine your shape is a rectangle that is 100 wide and 100 height. Your viewportWidth and viewPortHeightshould normally both be set to 100. So that Android knows the dimensions of the underlying shapes.

The width and height attributes tell Android what the default ("intrinsic") rendering size of the VectorDrawable should be. You can think of these like the width and height of a PNG or GIF (or SVG for that matter).

So the contents of your VectorDrawable could be defined over an area of 100x100. But if your width and height are 24x24, the contents will be scaled down from 100x100 to 24x24.

So that's why fiddling with the viewportWidth and viewPortHeight messes with the VectorDrawable. So for instance, if you change them to 50x50, you would end up with one corner of the shape scaled down to 24x24 - instead of the whole shape.

like image 98
Paul LeBeau Avatar answered Oct 11 '22 06:10

Paul LeBeau


Let's assume that the apple inside the canvas is your main vector drawable.Then h and w which are the height and width of the canvas respectively. So finally that h and w will be your drawable's viewportHeight and viewportWidth respectively

enter image description here

like image 42
Gk Mohammad Emon Avatar answered Oct 11 '22 08:10

Gk Mohammad Emon