我有一个有趣的问题。
<layer-list>
<item>
<shape android:shape="oval">
<size android:width="@dimen/cb_shape_size" android:height="@dimen/cb_shape_size"/>
<solid android:color="@color/cb_unchecked_solid"/>
<stroke android:width="@dimen/cb_shape_stroke"
android:color="@color/cb_checked_stroke"/>
</shape>
</item>
<item android:drawable="@drawable/main_cb_gps_off"
android:gravity="center"/>
</layer-list>
main_cb_gps_off 是一个 svg 文件。 在 Android Studio 中预览是这样的:
但是当我在手机(Android4.4.2)中运行项目时, View 喜欢这样:
而我在Android6.0的手机上运行项目时, View 和Android Studio的预览一样。 然后同时,我发现:
<layer-list>
<item android:drawable="@drawable/main_cb_gps_off"
android:gravity="center"/>
</layer-list>
这段代码运行在Android4.4.2,svg文件大小正常。 所以我不知道为什么当“图层列表”有两个项目时,svg 文件的大小会变大。我想知道。有什么解决办法吗?
最佳答案
如果您在 layer-list
中使用 drawable
,它将被缩放以适应它所在的 View 。
来自文档:
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate.
为避免缩放,您必须使用位图
:
To avoid scaling items in the list, use a
bitmap
element inside theitem
element to specify the drawable and define the gravity to something that does not scale, such as "center".
发件人:https://developer.android.com/guide/topics/resources/drawable-resource#LayerList
关于android - 从 SVG 设置图层列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39055995/