【问题标题】:What's alternative to 'AppBarLayout$ScrollingViewBehavior' in AndroidX?AndroidX 中“AppBarLayout$ScrollingViewBehavior”的替代方法是什么?
【发布时间】:2019-04-03 08:33:34
【问题描述】:

我最近将我的项目迁移到了 AndroidX。现在,当我打开包含以下代码的应用程序的特定页面时,应用程序崩溃

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="fill_vertical"
    android:clipToPadding="false"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
    >

Logcat 中的错误:

android.view.InflateException: Binary XML file line #119: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior
    Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior

我认为我必须用它在 AndroidX 中的替代行为来替换这种行为。但是那个替代代码是什么? 我搜索了https://developer.android.com/jetpack/androidx/migrate。但是没有找到AppBarLayout。

提前致谢。

【问题讨论】:

    标签: android androidx


    【解决方案1】:

    我找到了解决方案。 layout_behavior 行必须替换为:

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

    确保 build.gradle 中存在“材料”依赖项:

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

    【讨论】:

    • 谢谢@亨利医生 :)
    • 太好了,谢谢。这帮助我完成了向 AndroidX 的迁移。
    【解决方案2】:

    就我而言,我使用了这个:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    还要确保添加此依赖项:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多