【发布时间】:2019-05-13 12:07:33
【问题描述】:
我无法在 Android 活动中将矢量可绘制 xml 设置为背景。
我尝试通过设置android:background="@drawable/test_background"将其设置为背景
到我的活动的 Coordinator 布局根目录。
到 Coordinator 布局子约束布局
通过
app:srcCompat"= @drawable/test_background"ConstraintLayout的ImageView子代
上述方法均无效。我在设计预览中只能看到黑屏,并且我的应用程序崩溃并出现致命异常:
android.view.InflateException:二进制 XML 文件第 5 行:错误 膨胀类 android.support.design.widget.CoordinatorLayout
这是我的布局大纲:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/test_background"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:scrollbarStyle="outsideOverlay">
<android.support.constraint.ConstraintLayout>
<android.support.v7.widget.AppCompatImageView>
</android.support.v7.widget.AppCompatImageView>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
test_background drawable 是从 png 图像创建的 xml 矢量资源,在 Inkscape 中转换为 svg,并通过 Inkscape 插件导出为 xml 资源。 png 图像包含一种模式,我从未真正将其上的任何东西转换为路径。所以它看起来像这样:
<vector xmlns:ns0="http://schemas.android.com/apk/res/android"
ns0:name="svg869"
ns0:width="1382.2272dp"
ns0:height="2073.3408dp"
ns0:viewportWidth="666.666666667"
ns0:viewportHeight="1000.0"/>
但是,我确实确认插件正在成功导出 xml,因为我可以成功地将 xml 背景设置为图标(例如作为徽标/图标)。
我的问题是我无法将矢量设置为背景。
是否需要在可绘制对象中设置任何属性才能将其用作活动的背景?还是我做错了什么?
非常感谢您的帮助!
【问题讨论】:
标签: android android-vectordrawable