首页 > 解决方案 > 禁用 AppBar 滚动

问题描述

问题是将 AppBar 设置为顶部的动画(我想禁用滚动)

在下面的代码中,当我们滑动 nestedScrollview 时,appBar 滚动到顶部... 那么我想要得到什么结果? 我想禁用滚动 Appbar 但嵌套滚动视图(见下面的代码)与她的子视图可以滚动到顶部(结果“高度”将具有“match_parent”)与重叠的 AppBar

<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=".MainActivity">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@color/teal_200"
        app:layout_behavior="@string/behavior"
        app:elevation="0dp">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarStyle="insideInset"
            app:collapsedTitleGravity="center"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <TextView
                android:gravity="center"
                android:text="Do not scroll to top"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

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

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nestScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:fillViewport="true"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:background="@color/white"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="match_parent"
                android:id="@+id/jumpUrl"
                android:gravity="center"
                android:layout_height="wrap_content"
                android:background="@color/white"
                android:layout_gravity="center"
                android:drawableBottom="@drawable/ic_android_black_24dp"
                android:text="Scroll to top without scrolling AppBar" />

        </LinearLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

标签: android

解决方案


推荐阅读