首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >迁移项目中的androidx应用程序布局问题

迁移项目中的androidx应用程序布局问题
EN

Stack Overflow用户
提问于 2019-02-24 17:38:08
回答 1查看 6K关注 0票数 3

我最近把我的项目转化为雄激素。但是现在它有了一个致命的exception.when,我运行这个项目,我面临着坐标布局和appbarLayout的错误,并且与androidx不兼容。我想我必须使用androidx替代AppBarLayout,但我寻找它,但找不到任何替代。

代码语言:javascript
运行
复制
android.view.InflateException: Binary XML file line #36: 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

这是我的xml代码:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">


<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:fitsSystemWindows="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:toolbarId="@+id/toolbar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:layout_scrollInterpolator="@android:anim/decelerate_interpolator"
        app:contentScrim="?attr/colorPrimary">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/allAdsMain_recyclerView_mainCategories"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".all_ad_main" >

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/allAdsMain_recyclerView_ads"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

<Button
    android:id="@+id/allAdsMain_button_adRegister"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center"
    android:layout_marginBottom="5dp"
    android:background="@drawable/roundshapebtn"
    android:text="@string/call_for_price"
    android:textColor="@color/white"
    android:textDirection="rtl"
    android:textSize="24sp"
    app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-25 01:12:10

您仍然在引用NestedScrollView下的支持库依赖项。

更改:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

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

您已经在CoordinatorLayout中使用它了。下次遇到这种问题时,您可以在Android中使用完整的代码,同时尝试创建一个AppBarLayout并检查Android想要导入的版本的包。如果您的依赖项设置正确,则应该只有androidx选项,

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54854645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档