AppBarLayout不会折叠

切换到androidx后,以下代码停止工作。工具栏下方的TextView用于滚动内容,但现在不滚动。是否有解决此错误的解决方案?

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".Mainactivity">    
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appabr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_scrollflags="scroll|enterAlways">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.actionBar"
            app:layout_scrollflags="scroll|enterAlways"
            app:popuptheme="@style/ThemeOverlay.AppCompat.Light"
            app:title="Title" />
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.nestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
        app:layout_constraintTop_toBottomOf="@+id/appabr">

        <TextView
            android:id="@+id/tv_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="16dp"
            android:linespacingMultiplier="2"
            android:text="@string/aritical" />
    </androidx.core.widget.nestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
ygdbl 回答:AppBarLayout不会折叠

代替

androidx.constraintlayout.widget.ConstraintLayout

使用

android.support.design.widget.CoordinatorLayout

作为您的根布局

,

代替

androidx.constraintlayout.widget.ConstraintLayout

使用

androidx.coordinatorlayout.widget.CoordinatorLayout

我很笨TvT

本文链接:https://www.f2er.com/3085703.html

大家都在问