Search code examples
androidandroid-vectordrawable

Scale single vector drawable xml for all dpi and for different devices?


Before the Addition of Vector Drawable in Android SDK, developer had to create multiple version of images for different display resolutions. With Vector Drawable we need to create image only once as an xml file and we can scale it for all dpi and for different devices.

I had created a vector asset in studio

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/>
</vector>

It's placed in drawable folder and my hesitation is what I need to do to scale it for all dpi and for different devices ?

Can any one help me to make these more clear ?


Solution

  • No you don't need to scale by yourself. That is exactly what Vector Drawable solves, by providing multi-density graphics.

    If you're curious about how it works, check here: this link and this too