【发布时间】:2019-03-31 01:47:54
【问题描述】:
更新到 gradle 3.1.4 并移至 buildToolsVersion "27.0.3"
我正面临这个问题
android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable com.demo.android:drawable/ic_demo with resource ID #0x7f080160
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_demo.xml from drawable resource ID #0x7f080160
我尝试将 android:src 替换为 app:srcCompat 并添加 vectorDrawables.useSupportLibrary = true in defaultConfig
下面是布局文件代码
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_demo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone" />
</RelativeLayout>
更新: 我发现了一个问题。问题是一些矢量正在工作,其中一些不受支持,尽管它们是从相同来源以 SVG 格式创建的。谁能建议我将 PNG 转换为 SVG 文件。
【问题讨论】:
-
确保您的图像
/ic_demo位于res/drawable文件夹中而不是drawable-v24 -
粘贴您的 xml 代码。不看就很难调试。检查您是否在 xml 中收到错误
-
can't find resource in your project 错误表示
-
使用
AppCompatImageView而不是ImageView,这可能会解决您的问题。 -
不要使用这个应用程序:srcCompat="@drawable/ic_demo" 使用:android:src
标签: android android-layout gradle android-library