InflateException:为VectorDrawableCompat填充类ImageView时出错

wir*_*uma 6 android android-vectordrawable

VectorDrawableCompat 终于进入了SDK 23中的支持库.但它似乎没有用,或者我可能错过了一些东西.

drawable/mypic.xml:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<group
    android:name="rotationGroup"
    android:pivotX="300.0"
    android:pivotY="300.0"
    android:rotation="45.0" >
    <path
        android:name="v"
        android:fillColor="#000000"
        android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</group>
</vector>
Run Code Online (Sandbox Code Playgroud)

fragment_bla.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/mypic"
    android:scaleType="centerCrop" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

此代码适用于Lollipop,但不适用于KitKat.我错过了什么?


例外:

09-06 14:26:53.637  31820-31820/com.bla E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.bla, PID: 31560
android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
        at android.view.LayoutInflater.createView(LayoutInflater.java:623)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
        at com.hohero.fragment.Intro1Fragment.onCreateView(Intro1Fragment.java:14)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
Run Code Online (Sandbox Code Playgroud)

小智 18

我相信问题出 android:src="@drawable/mypic"在你的imageView设置中.

改为 app:srcCompat="@drawable/mypic"

然后你应该好好去.

更多详情,请参阅:https: //medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.mvuq06x1k