在API中:19我面临这种Inflate Exception,但我使用的AppCompatDrawableManager支持API中的矢量绘图:19
三个例外 1.“充气图像”按钮出错 2.资源$ NotFoundException来自可绘制资源的文件res / drawable / bckg_icon.xml 3. org.xmlpull.v1.XmlPullParserException:二进制XML文件行#1:无效的可绘制标记向量
我试图去掉ImageButton drawable src这四种格式(hdpi,mdpi,xxhdpi等) 我的实施: xml文件是fragmnet xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layoutPreviewActionBar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/previewFragment"
android:layout_width="fill_parent"
android:layout_height="@dimen/action_bar_height"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="25dp"
android:layout_marginLeft="10dp"
android:text="00:00"
android:id="@+id/timeduration"
android:textColor="@color/colorPrimary"/>
<ImageButton
android:id="@+id/localVideo"
android:layout_width="@dimen/icon_width"
android:layout_height="@dimen/icon_height"
android:layout_centerVertical="true"
android:layout_marginRight="14.1dp"
android:layout_toLeftOf="@+id/call"
android:background="@drawable/bckg_icon"
android:layout_margin="5dp"
android:src="@drawable/video_icon" />
<ImageButton
android:id="@+id/call"
android:layout_width="@dimen/icon_width"
android:layout_height="@dimen/icon_height"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/initiate_call_button"
android:clickable="true"
android:layout_margin="5dp"
app:srcCompat="@drawable/start_call" />
<ImageButton
android:id="@+id/localAudio"
android:layout_width="@dimen/icon_width"
android:layout_height="@dimen/icon_height"
android:layout_centerVertical="true"
android:layout_marginLeft="14.1dp"
android:layout_toRightOf="@+id/call"
android:background="@drawable/bckg_icon"
app:srcCompat="@drawable/mic_icon" />
</RelativeLayout>
My Fragment java类那些drawables实现:
rootView = inflater.inflate(R.layout.preview_actionbar_fragment, container, false);
mAudioBtn = (ImageButton)rootView.findViewById(R.id.localAudio);
mVideoBtn = (ImageButton)rootView.findViewById(R.id.localVideo);
mCallBtn = (ImageButton)rootView.findViewById(R.id.call);
timdura= (TextView)rootView.findViewById(R.id.timeduration);
c=mActivity;
booking_id=mActivity.bookingId;
drawableStartCall = AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.initiate_call_button);
drawableEndCall =AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.end_call_button);
drawableBckBtn = AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.bckg_icon);
我的logCat详细信息:
I/com. .MainActivity: OnAttach PreviewControlFragment
I/com.therightdoctors.dpmdoctor.MainActivity: OnCreate PreviewControlFragment
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41a22cf8)
W/dalvikvm: threadid=1: uncaught exception occurred
E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.therightdoctors.dpmdoctor/com.therightdoctors.dpmdoctor.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.therightdoctors.dpmdoctor.ui.PreviewControlFragment.onCreateView(PreviewControlFragment.java:165)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
at android.app.Activity.performStart(Activity.java:5353)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/bckg_icon.xml from drawable resource ID #0x7f02005c
at android.content.res.Resources.loadDrawable(Resources.java:2170)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3579)
at android.widget.ImageView.<init>(ImageView.java:123)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:60)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.therightdoctors.dpmdoctor.ui.PreviewControlFragment.onCreateView(PreviewControlFragment.java:165)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
at android.app.Activity.performStart(Activity.java:5353)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binar
我试过StackOverflow一些类似的问题无法正常工作
2.使用app:srcCompat而不是XML中的android:src属性
仅在API中出现问题:19个较低的DPI设备如何处理这些类型的异常
答案 0 :(得分:4)
我知道它已经有一段时间了,但我认为你在这里使用VectorDrawable
作为ImageButton
的背景:
<ImageButton
android:id="@+id/localVideo"
android:layout_width="@dimen/icon_width"
android:layout_height="@dimen/icon_height"
android:layout_centerVertical="true"
android:layout_marginRight="14.1dp"
android:layout_toLeftOf="@+id/call"
android:layout_margin="5dp"
android:src="@drawable/video_icon"
android:background="@drawable/bckg_icon />" <!-- <- here is your problem -->
我发现使用VectorDrawable
作为TextView
的背景,EditText
,Button
,ImageButton
等使用android:background="..."
导致崩溃在API 19之前和之前,因为旧设备上的android:background
使用旧的API,并且当android尝试给你的VectorDrawable
充气时,它无法解析它并崩溃。请注意,当您使用app:srcCompat
作为ImageView
的源图像时,您正在使用Compat库并且没有问题。
要解决此问题,您可以使用以下3种方法之一:
ImageView
并将app:srcCompat
设置为VectorDrawable
VectorDrawable
templating-resources View
的背景设置为VectorDrawable
,并在较低的API中将其设置为BitmapDrawable
(例如png文件) 答案 1 :(得分:2)