Android 滚动AppBarLayout中的第二个子项
我试图获得这样的效果,如果用户滚动一个Android 滚动AppBarLayout中的第二个子项,android,android-coordinatorlayout,android-appbarlayout,custom-scrolling,Android,Android Coordinatorlayout,Android Appbarlayout,Custom Scrolling,我试图获得这样的效果,如果用户滚动一个RecyclerView某个布局与回收器一起向上滚动,然后消失在工具栏后面 使用坐标布局可以获得类似的行为,这可以通过设置 app:layout_behavior="@string/appbar_scrolling_view_behavior" 对所说的回收商,做什么 <android.support.design.widget.AppBarLayout android:layout_width="match_parent"
RecyclerView
某个布局与回收器一起向上滚动,然后消失在工具栏后面
使用坐标布局
可以获得类似的行为,这可以通过设置
app:layout_behavior="@string/appbar_scrolling_view_behavior"
对所说的回收商,做什么
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
此外,如果我在AppBarLayout
中放置第二个子项,并将app:layou\u scrollFlags
设置为该子项,则获得的效果相同,两个布局都与回收器一起滚动
我试图实现的是将第一个子项(工具栏)固定到位,并让第二个子项(aLinearLayout
)滚动并隐藏在工具栏后面。不幸的是,我无法做到这一点
是否可以不使用第三部分库?
提前感谢,对不起我的英语。最后,我找到了一种实现这种行为的方法,将坐标布局包括在线性布局中,并通过将工具栏移动到外部(根)级别,使第二个子(线性布局)成为第一个子(线性布局)
之前的层次结构:
<CoordinatorLayout>
<AppBarLayout>
<ToolBar>
<LinerarLayout>
之后的层次结构:
<LinearLayout>
<ToolBar>
<CoordinatorLayout>
<AppBarLayout>
<LinearLayout>
exmaple:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="48dp" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorSecondaryLight"
android:orientation="vertical"
app:layout_scrollFlags="scroll"/>
</com.google.android.material.appbar.AppBarLayout>
.
.
.
.
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
.
.
.
.
希望有帮助 我在这里添加了一条评论以供参考,因为这并不是问题的真正答案,而是更多的解决方法:一个简单的解决方案是将布局的第二个子项设置为RecyclerView的标题,并简单地将工具栏固定在顶部。这听起来不错,但如果我们想更新标题,可能会带来一些麻烦。