Android Vector Asset Studio gives extra padding to some vector images

后端 未结 4 1046
无人共我
无人共我 2021-01-04 02:06

I\'m trying to import some icons from Material Vector package in Vector Asset Studio.

But they come with padding.

Why does this happen and how can I

4条回答
  •  有刺的猬
    2021-01-04 02:29

    You can adjust for any "implicit" padding that may be contained within a VectorDrawables source image (.SVG, .PSD) by setting your ImageViews android:scaleType to the appropriate value so it can handle the padding that is secretly contained in the VectorDrawables source image. You will also need to set android:adjustViewBounds="true".

    For example, lets say your VectorDrawable has some really annoying padding at the start of the image when you display it. You have no idea why it's there because you aren't setting any android:paddingStart on the ImageView... what you need to do is set the ImageViews android:scaleType to fitStart and android:adjustViewBounds to true.

    tl;dr

    Adjust your ImageViews android:scaleType to handle any "implicit" padding that is contained in your VectorDrawables source file (.SVG, .PSD). Also set android:adjustViewBounds="true".

    Quick Example:

    
               android:adjustViewBounds="true"
               android:scaleType="fitStart"
               app:srcCompat="@drawable/vector_with_implicit_padding_at_start"
    />
    

    This will remove that annoying "implicit" padding that was at the start of your VectorDrawable.

    Note: Adjust the android:scaleType according to your rendering needs.

提交回复
热议问题