Search code examples
androidsvgandroid-vectordrawable

How to fit VectorDrawable to ImageView and remove unnecessary paddings


For my Android app I've created such layer list from two vector Drawable.

The xml-code

Image Drawable

I want to put this image into ImageView, but I have a problem with paddings which I can't remove (marked in red)enter image description here.

To solve this issue I've already applied follow steps:

  1. Explicitly set paddings to 0 value
  2. Set "AdjustViewBound" to true
  3. Played with "fitType" attributes.

None of this hadn't been worked for me. Please help me to resolve this problem.


Solution

  • You should get a whole drawable with the circle and person in one vector. But if you really need these two files to be separated, you must change the path in the XML code.

    Accordingly to this https://stackoverflow.com/a/50114171/3368784 you can resize your path by rewriting your primary_dark_color_circle.xml as:

    <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
        <group
            android:pivotX="12"
            android:pivotY="12"
            android:scaleX="1.2"
            android:scaleY="1.2">
            <path
                android:fillColor="#0088CC"
                android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0" />
        </group>
    </vector>