首页 > 解决方案 > android 行为在 androidx.core.widget.NestedScrollView 中不起作用

问题描述

我有一个CoordinatorLayout并且有AppBarLayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    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"
    tools:context=".Pages.Artist.Show">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/AppBar">
        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbarLayout"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:collapsedTitleGravity="center">
            <ImageView
                android:contentDescription="@null"
                android:id="@+id/ArtistImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </androidx.core.widget.NestedScrollView>
    </com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

NestedScrollView无法设置layout_behavior

为什么我们在 androidx 中没有 layout_behavior 呢?

标签: androidxmlandroid-studioandroid-layoutandroid-coordinatorlayout

解决方案


您可以在NestedScrollView标记中设置这样的布局行为。

app:layout_behavior="@string/appbar_scrolling_view_behavior"


推荐阅读