【问题标题】:Could not inflate Behavior subclass android.support.design.widget.scroll_behavior无法膨胀行为子类 android.support.design.widget.scroll_behavior
【发布时间】:2017-02-24 11:23:11
【问题描述】:

这是我使用坐标布局和视图寻呼机的活动。

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <include layout="@layout/venue_app_bar_content" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            app:tabIndicatorColor="@android:color/white"
            app:tabMode="scrollable"
            app:tabSelectedTextColor="@color/white"
            app:tabTextColor="@color/white50" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

当运行应用程序时,它会因消息而崩溃: 引起:java.lang.RuntimeException:无法膨胀行为子类android.support.design.widget.scroll_behavior

【问题讨论】:

  • 以上代码在android.support.design.widget.CoordinatorLayout中。
  • 您似乎为 appbar_scrolling_view_behavior 资源字符串设置了自己的(不正确的)值。支持库中的值为android.support.design.widget.AppBarLayout$ScrollingViewBehavior。查看您的res/values*/ 文件夹,很可能是在strings.xml 文件中,看看那里是否有值。如果是,请删除它。
  • 对,这就是当CoordinatorLayout 无法创建layout_behavior 中指定的类的实例时得到的结果。它试图在某个地方创建android.support.design.widget.scroll_behavior 的实例,所以要弄清楚它是从哪里得到不正确的类名的。如果它不是来自您发布的内容,其余的堆栈跟踪将帮助您找出位置。
  • 对不起!我已经声明了一个具有相同键的字符串变量。谢谢@MikeM。

标签: android android-design-library


【解决方案1】:

您应该尝试删除strings.xml文件中的字符串资源。这就是解决我的问题的方法。

【讨论】:

    【解决方案2】:

    如果你有 androidx,那么你应该手动将 XML 中使用的类映射到新的类:

    https://developer.android.com/jetpack/androidx/migrate

    【讨论】:

      【解决方案3】:

      layout_behavior 行必须替换为:

      app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
      

      确保 build.gradle 中存在此依赖项:

      implementation 'com.google.android.material:material:1.0.0'
      

      【讨论】:

      • 谢谢!!!我使用的是 app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" 并将其替换为推荐。
      猜你喜欢
      • 1970-01-01
      • 2017-12-19
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      相关资源
      最近更新 更多