在FloatingActionButton上设置id时抛出InflateException

时间:2016-08-04 20:41:49

标签: c# android xamarin material-design inflate-exception

我在主要活动中添加了一个浮动操作按钮控件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="@dimen/main_fab_margin"
            android:layout_marginBottom="@dimen/main_fab_margin"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_main_fab"
            app:fabSize="normal"
            app:backgroundTint="@color/color_primary"
            app:elevation="@dimen/main_fab_elevation"/>
    </RelativeLayout>

    <!-- Pull-out navigation drawer (a.k.a hamburger menu) -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/navigationmenu"
        app:headerLayout="@layout/drawerheader" />

</android.support.v4.widget.DrawerLayout>

这会抛出一个类似于:

的InflateException
Android.Views.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

浮动操作按钮是RelativeLayout的子项,它是android.support.v4.widget.DrawerLayout的子项。

现在是奇怪的部分,当我删除

android:id="@+id/main_fab"

从上面的代码中,一切都很完美。

我不知道是什么原因引起的。我真的需要为按钮设置一个id,这样我就可以控制代码隐藏中的点击次数。

有什么想法吗?

更新

堆栈追踪:

Unhandled Exception:

Android.Views.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

08-04 16:49:39.952 E/AndroidRuntime(16025): FATAL EXCEPTION: main
08-04 16:49:39.952 E/AndroidRuntime(16025): Process: RA16mobile.RA16mobile, PID: 16025
08-04 16:49:39.952 E/AndroidRuntime(16025): android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:278)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:379)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:328)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1211)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1943)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.Choreographer.doFrame(Choreographer.java:606)
08-04 16:49:39.952 E/AndroidRuntime(16025):     at android.view.Choreograp
08-04 16:49:40.000 I/Process (16025): Sending signal. PID: 16025 SIG: 9

1 个答案:

答案 0 :(得分:1)

尝试核对obj/bin个文件夹,重新启动IDE,然后进行干净部署。 (即adb uninstall packagename)。关于Error inflating class android.support.design.internal.NavigationMenuItemView,我经常看到这个问题,似乎已经解决了这个问题。

我认为这是一个Xamarin特定的错误,直到我在Native Java中遇到它。基本上按照相同的步骤解决了这两个领域的问题。