Android Vector Asset Studio为某些矢量图像提供了额外的填充 [英] Android Vector Asset Studio gives extra padding to some vector images
问题描述
我正在尝试从Vector Asset Studio中的Material Vector包中导入一些图标.
I'm trying to import some icons from Material Vector package in Vector Asset Studio.
但是它们带有填充.
为什么会发生这种情况,我该如何删除?
Why does this happen and how can I remove it?
这很不方便,因为这意味着如果我希望我的图标在XML中为17dp x 17dp,那么我需要将其设置为大于17x17的长度以弥补填充.
This is inconvenient because this means if I want my icon to be 17dp x 17dp in XML, then I need to set it more than 17x17 to make up for the padding.
推荐答案
通过设置ImageViews
android:scaleType
设置为适当的值,以便它可以处理VectorDrawables
源图像中秘密包含的填充.您还需要设置android:adjustViewBounds="true"
.
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"
.
例如,假设您的VectorDrawable
在显示图像时在图像的开头有一些非常令人讨厌的padding
.您不知道为什么会出现它,因为您没有在ImageView
上设置任何android:paddingStart
...您需要做的是将ImageViews
android:scaleType
设置为fitStart
,将android:adjustViewBounds
设置为
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;博士
调整ImageViews
android:scaleType
以处理VectorDrawable
的源文件(.SVG
,.PSD
)中包含的任何隐式"填充.还要设置android:adjustViewBounds="true"
.
Adjust your ImageViews
android:scaleType
to handle any "implicit" padding that is contained in your VectorDrawable
s source file (.SVG
, .PSD
). Also set android:adjustViewBounds="true"
.
快速示例:
<ImageView android:id="@+id/vectorDrawable_imageView"
<!--Other ImageView settings-->
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="@drawable/vector_with_implicit_padding_at_start"
/>
这将删除VectorDrawable
开始时的烦人的隐式"填充.
This will remove that annoying "implicit" padding that was at the start of your VectorDrawable
.
注意:根据您的渲染需求调整android:scaleType
.
Note: Adjust the android:scaleType
according to your rendering needs.
这篇关于Android Vector Asset Studio为某些矢量图像提供了额外的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!