Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Android's VectorDrawable properties

I need help understanding some of the properties of VectorDrawable that is defined by XML.

When i import a new vector asset using Android Studio, It generates something like:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">

    <path 
        android:fillColor="#000000"
        android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
</vector>

By default the width, height, viewportHeight and viewportWidth are being set to some default Material design value.

Since we are dealing with vectors and not pixel images. My questions are:

  • why is it required to set a size (width, height, etc)?
  • If i need to use the same vector xml for multiple sizes, how to override this 24dp value without creating multiple vector xml's which of course defeats the whole purpose!
like image 840
TareK Khoury Avatar asked Feb 28 '16 13:02

TareK Khoury


1 Answers

Adding @dimen in xml vector gives error Error:Error: Width (0) and height (0) cannot be <= 0

like image 154
user1866731 Avatar answered Sep 20 '22 18:09

user1866731