How to fit VectorDrawable to ImageView and remove unnecessary paddings

这一生的挚爱 提交于 2019-12-04 05:12:06

问题


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

The xml-code

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

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.


回答1:


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>


来源:https://stackoverflow.com/questions/53411647/how-to-fit-vectordrawable-to-imageview-and-remove-unnecessary-paddings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!