android - 从 SVG 设置图层列表项

标签 android svg layer-list

我有一个有趣的问题。

<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>

ma​​in_cb_gps_off 是一个 svg 文件。 在 Android Studio 中预览是这样的:

enter image description here

但是当我在手机(Android4.4.2)中运行项目时, View 喜欢这样:

enter image description here

而我在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 the item 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/

相关文章:

android - 从 ImageCardView 中移除背景

javascript - 如何动态添加另一行?

javascript - 如何使用 Javascript 检测 SVG 动画并显示/隐藏 Flash/SVG 对象?

android - 带有图层列表的自定义绘图

java - 加密 zip

java - Java android studio 项目中的NoFileFoundException

android - 无法在 ViewFlipper 中的 ScrollView 上水平 throw 以冒泡

javascript - 在 SVG 中绘制 "squiggly line"

android - 图层列表:使用填充移动底部的形状线

android - 如何在 xml 中重新创建此背景?