为什么在xml中使用向量drable时抛出Inflact Exception?

时间:2017-10-25 10:08:22

标签: android android-layout

我在ImageView的{​​{1}}中使用了vector drawable。

这是我的代码:

android

<ImageView android:layout_width="320dp" android:layout_height="320dp" app:srcCompat="@drawable/app_logo" android:id="@+id/titleImageView" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:layout_marginTop="12dp" /> 中运行应用时出现了这些错误。

  

致命例外:主要   处理:com.nuvo.driver,PID:4303
  java.lang.RuntimeException:无法启动活动   ComponentInfo {com.nuvo.driver / com.nuvo.driver.SignUp_Activity_}:   android.view.InflateException:二进制XML文件行#16:错误   膨胀类ImageButton

提前感谢您的时间。

2 个答案:

答案 0 :(得分:1)

你必须做两个选择来解决这个问题:

  1. 使用android:src代替app:srcCompat 或
  2. 使用vectore dwable你必须改变 build.gridle文件中的android.defaultConfig.vectorDrawables.useSupportLibrary = true

答案 1 :(得分:1)

如果您在build.gradle文件中使用此代码:

android.defaultConfig.vectorDrawables.useSupportLibrary = true

我认为你正在使用矢量drawable用于按钮或textview或... 这个行为使您的应用程序在5以下的Android上例外。 如果我猜的是真的使用这个结构: Is it possible to use VectorDrawable in Buttons and TextViews using android:DrawableRight?