Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 739
AlexF Avatar asked Nov 21 '18 12:11

AlexF


People also ask

What is VectorDrawable?

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.

How to put image in drawable XML file?

Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure.

How to reference an image in Android studio?

To use an image resource, add your file to the res/drawable/ directory of your project. Once in your project, you can reference the image resource from your code or your XML layout. Either way, it's referred to using a resource ID, which is the file name without the file type extension. For example, refer to my_image.

How to add image in XML file in Android studio?

xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.


1 Answers

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>
like image 167
Giovanne Avatar answered Nov 01 '22 10:11

Giovanne