我无法将矢量可绘制 xml 设置为 Android Activity 中的背景。
我尝试通过设置 android:background="@drawable/test_background"
将其设置为背景
到我的 Activity 的协调器布局根。
到协调器布局子约束布局
发送至
ImageView
ConstraintLayout
的 child 通过app:srcCompat"= @drawable/test_background"
以上方法均无效。我在设计预览中只能看到黑屏,并且我的应用程序因致命异常而崩溃:
android.view.InflateException: Binary XML file line #5: Error inflating class 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 可绘制对象是从 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 背景设置为图标(例如作为 Logo /图标)。
我的问题是我无法将矢量设置为背景。
我需要在可绘制对象中设置任何属性才能将其用作 Activity 的背景吗?还是我做错了什么?
非常感谢您的帮助!
最佳答案
关于android - 如何使用 Android 矢量绘图作为 Activity 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56112020/