标签: android-nestedscrollview

Android Nested Scrollview不滚动

我有一个嵌套ScrollView,其中包含线性布局内的内容.

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto"
    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.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

我在ViewPager中有这个布局,ViewPager在CordinatorLayout里面.

<android.support.design.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
Run Code Online (Sandbox Code Playgroud)

现在,当我滚动视图时,视图不会滚动.但由于布局位于Cordinator布局内,因此向上移动直到ToolBar被隐藏.但它没有向上滚动.

这是我的主要活动xml,视图寻呼机位于选项卡式布局中.

<android.support.design.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

           <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:attrs="http://schemas.android.com/apk/res-auto"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            <FrameLayout
                android:id="@+id/titleContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"    
                android:gravity="center">

                <com.CustomFontTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Toolbar Title"
                    android:textColor="#ffffff"
                    attrs:customFont="handyman_bold"
                    android:textSize="8pt"
                    android:layout_marginLeft="-20dp"
                    android:id="@+id/toolbar_title"/>
            </FrameLayout>

            <ImageButton
                android:id="@+id/btn_ToolBarRightBtn"
                android:layout_width="32dp"
                android:layout_height="28dp"
                android:tag="0" …
Run Code Online (Sandbox Code Playgroud)

android android-nestedscrollview

8
推荐指数
1
解决办法
1万
查看次数

当与 viewpager 和 recyclerview 一起使用时,CollapsingToolbarLayout 的部分内容变得粘在上面

我正在尝试实现这样的布局:

在此处输入图片说明

问题是,当向上滚动卡片时,它会接触到工具栏,并且不再像这样向上滚动:

在此处输入图片说明

我希望它向上滚动直到 viewpager 填满屏幕,即至少矩形卡应该向上滚动到工具栏之外(即使 tabLayout 也可以向上滚动)。但我不希望它在顶部保持粘性。

主要布局在这里:

 <?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:showIn="@layout/activity_main">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/background_dark"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbarCollapse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:minHeight="190dp"
                android:src="@drawable/ic_launcher_foreground"
                app:layout_collapseMode="parallax" />


            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />

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


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


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:behavior_overlapTop="90dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:id="@+id/lin"
            android:nestedScrollingEnabled="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include layout="@layout/debit_card_item" />


            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:layout_marginTop="40dp"
                android:background="?attr/colorPrimary" />


            <androidx.viewpager.widget.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

        </LinearLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

寻呼机的片段位于 NestedScrollView 中,如下所示:

<?xml …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview

8
推荐指数
1
解决办法
888
查看次数

在RecyclerViewPager中添加Recyclerview

RecyclerviewRecyclerViewPager(https://github.com/lsjwzh/RecyclerViewPager)中添加了一个项目.RecyclerView当我触摸它时,我想滚动.

我试过了 :

    View.OnTouchListener listener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_DOWN:
                    mRecyclerViewPager.requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    mRecyclerViewPager.requestDisallowInterceptTouchEvent(false);
                    break;
            }
            return false;
        }
    };
    mRecyclerView.setOnTouchListener(listener);
Run Code Online (Sandbox Code Playgroud)

但我有时只能滚动RecyclerView.

我认为它可以通过执行来sloved NestedScrollingParentRecyclerViewPager或改变onTouchEventRecyclerViewPager.但我不熟悉他们.

在此输入图像描述

android-recyclerview android-touch-event android-nestedscrollview

7
推荐指数
1
解决办法
1519
查看次数

如何在NestedScrollView中随时(平滑地)获得滚动百分比?

我想在滚动时更改工具栏的alpha,如下所示:

在此输入图像描述

首先,工具栏是透明的,通过滚动到底部,它将越来越可见,最后它将是完全不透明(可见).

我的布局结构是:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax">

            ....

        </RelativeLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

         ....

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

嵌套的scrollview的内容将从服务器动态更改,所以我不知道它的高度.

我刚刚发现了两种检测scrollY的方法:

  1. addOnScrollChangedListener:

    scroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
     @Override
     public void onScrollChanged() {
        // use scroll.getScrollY()     
    }
    });
    
    Run Code Online (Sandbox Code Playgroud)
  2. setOnScrollChangeListener:

    scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
    
    }
    });
    
    Run Code Online (Sandbox Code Playgroud)

但这些方式都不顺利.例如,如果您检查scrollY(通过使用log.d())的值,您将看到如下内容:

scrollY: 58 …
Run Code Online (Sandbox Code Playgroud)

android scroll scrollview android-nestedscrollview

7
推荐指数
2
解决办法
2488
查看次数

在BottomSheetDialog内的Viewpager内嵌套滚动

精简版:

如何设置NestedScrollingChildNestedScrollingParent与这些孩子的倍数。

长版

我实现了一个,BottomSheetDialogFragment它的布局包含一个ViewPager,这个 viewpager 的适配器包含一个RecyclerView.

现在,问题是,由于NestedScrollingParent此时底片的协调器布局仅支持一个direct NestedScrollingChild,因此只能嵌套滚动适配器的第一个片段。

我的意思是,无论何时setAdapter在 viewpager 上调用,第一项都支持嵌套滚动。但是在我更改页面后,新页面现在不会滚动。然后当我回到上一页时,它仍然支持滚动。

另外,我注意到如果可以滚动的片段或页面被破坏,则后续页面现在可以滚动,这意味着后面的页面成为底部页面的滚动子页面。问题是现在获得滚动能力的页面不是当前项目而是前一个(我的适配器必须维护 3 个片段)。

概括:

setAdapter

  • 片段 0 可以滚动
  • 然后将页面更改为片段 1 后,片段 1 无法滚动
  • 但是切换到片段 2,然后回到片段 1 允许片段 1 滚动(因为我猜是因为片段 0 被破坏了)

android scroll android-fragments android-viewpager android-nestedscrollview

7
推荐指数
1
解决办法
2501
查看次数

如何在viewPager的视图顶部使用nestedScrollView中的viewpager

由于viewpager,我无法滚动nestedScrollView.那么让我在这里解释一下我想要创建的布局设计:

enter image description here

NestedScrollView中有FrameLayout,标签布局有viewpager.Viewpager用无尽的recylerview(Pagination)加载三个片段.

这是布局xml代码:

<android.support.design.widget.CoordinatorLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.plowns.droidapp.activites.HomeActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>


    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="50dp"
    android:background="@color/colorPrimary" />


<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedscrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@color/trans">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="260dp">

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="55dp"
                    app:cardCornerRadius="5dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <ImageView
                            android:id="@+id/txt_edit_icon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/ic_mode_edit"
                            android:tint="@color/blue_plowns" />

                        <TextView
                            android:id="@+id/txt_child_name"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="50dp"
                            android:ellipsize="end"
                            android:gravity="center_vertical"
                            android:minHeight="5dp"
                            android:text="Satwinder Singh"
                            android:textAppearance="?android:attr/textAppearanceListItemSmall"
                            android:textColor="@android:color/black"
                            android:textSize="18sp" …
Run Code Online (Sandbox Code Playgroud)

android android-layout xml-layout android-viewpager android-nestedscrollview

7
推荐指数
1
解决办法
1772
查看次数

防止Bottom Sheet祖先视图中的滚动

我有一个CoordinatorLayout包含两个NestedScrollViews,一个有ScrollingViewBehavior,另一个有BottomSheetBehavior和扮演BottomSheet角色,问题是当我拖动时BottomSheet,第一个NestedScrollView滚动:

在此输入图像描述

我的期望:
当我滚动时BottomSheet,另一个NestedScrollView不应该滚动

我试了一下:
我创建了一个自定义的行为和覆盖onInterceptTouchEvent,在事件属于BottomSheet返回true和调用dispatchTouchEventBottomSheet,该功能可以防止NestedScrollView滚动,但BottomSheet不能滚动本身并单击事件BottomSheet孩子没有工作了.

这是我的布局:

<android.support.design.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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:ignore="UnusedAttribute">

<include
    layout="@layout/toolbar"/>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="?actionBarSize"
    android:background="#ff0"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <Button
            android:id="@+id/button_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:background="@android:color/holo_green_dark"
            android:padding="16dp"
            android:text="Button 1"
            android:textColor="@android:color/white"/>

        <Button
            android:id="@+id/button_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-coordinatorlayout android-nestedscrollview bottom-sheet

7
推荐指数
1
解决办法
2489
查看次数

使用内部的NestedScrollView处理VerticalViewPager的滚动

背景:

我使用的是ViewPager的变体,它不是在水平方向上滚动,而是在垂直方向上滚动.

VerticalViewPager: https ://android.googlesource.com/platform/packages/apps/DeskClock/+/master/src/com/android/deskclock/VerticalViewPager.java

android.support.v4.app.FragmentStatePagerAdapter用于设置内容VerticalViewPager.

我创建并返回一个新的实例android.support.v4.app.Fragment,从FragmentStatePagerAdapter每一次getItem()FragmentStatePagerAdapter下面所列称为:

@Override
public Fragment getItem(int position) {
   return  PreviewFragment.getNewFragmentInstance(position);
}
Run Code Online (Sandbox Code Playgroud)

PreviewFragment呈现可能不适合屏幕的内容.为了显示不适合屏幕的所有内容,将其android.support.v4.widget.NestedScrollView用作PreviewFragment布局的父元素 .

问题:

内容PreviewFragment按预期滚动到位置0.但是,为了切换到下一页,必须多次执行甩动或滑动操作,因此向位置1的页面滑动是非常困难的.

此外,投掷或滑回到位置0非常困难或几乎不可能.

需要:

Fling或swipe或切换到下一个实例PreviewFragment应该是平滑的.换句话说,滚动内容应该是平滑的,同时请记住,滑动到下一页也应该顺利工作.

如上所述链接到示例项目

android scrollview android-viewpager nestedscrollview android-nestedscrollview

7
推荐指数
1
解决办法
612
查看次数

检查nestedscrollview中的recyclelerview滚动状态

我在NestedScrollView中使用了recyclelerview,我希望在滚动后将搜索栏固定到操作栏,并且必须在搜索栏下显示recyclelerview项目,我需要为我的recyclerview项目进行延迟加载(滚动到结束后从服务器加载下一项)为此,我需要检查recyclerview滚动更改状态,当我在nestedscrollview中使用recyclelerview时,我无法做到这一点.我尝试使用nestedscrollview滚动状态更改侦听器,它不会给我我想要的东西,也不能正常工作.

如果将嵌套滚动视图放在recyclerview中,则它不起作用.我有懒惰加载recyclelerview但相同的布局包含其他布局,如滑块,菜单然后recyclerview.我想滚动完整的布局,当recyclerview结束onscroll然后onload执行从Internet获取更多项目并加载recylerview.

在这里你看到我的代码:

我的布局xml代码

 <android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/main_activity_background">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@color/colorPrimaryDark"
            app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v4.view.ViewPager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:background="@drawable/bg_gradient"
                    android:orientation="vertical"
                    android:gravity="center_horizontal"
                    android:paddingBottom="5dp"
                    android:paddingLeft="@dimen/spacing_large"
                    android:paddingRight="@dimen/spacing_large"
                    android:paddingTop="@dimen/spacing_mxlarge">


                    <LinearLayout
                        android:id="@+id/layout_dots"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:orientation="horizontal" />


                </RelativeLayout>

            </RelativeLayout>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:contentInsetStartWithNavigation="0dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:contentInsetLeft="0dp"
            android:contentInsetStart="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            android:contentInsetRight="0dp"
            android:contentInsetEnd="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetEnd="0dp">

            <LinearLayout
                android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview android-nestedscrollview

7
推荐指数
1
解决办法
358
查看次数

如何实现具有两个固定视图的“双”折叠工具栏

我正在尝试实现如图所示的布局。
这就是我希望它工作的方式
所以我希望在用户滚动到某个点后有两个固定在屏幕顶部的视图。其他视图应该折叠起来,直到完全隐藏为止(视图 3 除外,它基本上是布局的主视图。到目前为止,我已经尝试了几种方法。其中一种比较
有效,是将折叠工具栏与可固定视图 1 和Pinnable View 2 锚定到其他视图(我附上了代码片段,这样你就知道我实现了什么)。这种方法的问题是,因为这些可固定视图不在nestedScrollView内部,所以当用户使用时不可能滚动从这两个视图开始滚动,
所以我的问题是,使用我当前的方法是否可以达到预期的效果,或者是否有其他方法可以做到这一点?

<?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">

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

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <View
                android:id="@+id/view_1"
                android:layout_width="match_parent"
                android:layout_marginBottom="32dp"
                android:layout_height="200dp"
                android:background="#0071BD"
                app:layout_collapseMode="parallax">
            </View>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:layout_marginTop="32dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".ScrollingActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <View
                android:id="@+id/view_2"
                android:layout_width="wrap_content"
                android:background="#5495BD"
                android:layout_height="300dp"/>

            <View
                android:id="@+id/pinnable_view_2_anchor_view"
                android:layout_width="match_parent"
                android:layout_height="41dp"
                android:background="@null" />

            <View
                android:id="@+id/view_3"
                android:layout_width="match_parent"
                android:background="#57B1BC"
                android:layout_height="1000dp" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <View
        android:id="@+id/pinnable_view_1"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="#00015E"
        android:nestedScrollingEnabled="true"
        app:layout_anchor="@id/app_bar_layout_view"
        app:layout_anchorGravity="bottom">
    </View>

    <View …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-collapsingtoolbarlayout android-nestedscrollview

7
推荐指数
1
解决办法
2090
查看次数