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>
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>
该代码在Lollipop中有效,但在KitKat中不起作用。我想念什么?
异常(exception):
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)
最佳答案
我相信问题是
imageView设置中的android:src="@drawable/mypic"
。
更改为app:srcCompat="@drawable/mypic"
那你应该很好。
更多详细信息,请参阅:
https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.mvuq06x1k