美文网首页
Android CoordinatorLayout+AppBa

Android CoordinatorLayout+AppBa

作者: 清朝公主大清正黄旗 | 来源:发表于2022-05-25 10:13 被阅读0次

    我百度查了一些,然后看了别人的代码,都是 CoordinatorLayout+AppBarLayout 就能实现一直向上滑动,我改写的都写了,但是还是只有最下面的列表会滑动,上面的部分就是一直不动,最后看了以前自己写的老代码,还需要加一个CollapsingToolbarLayout 然后立马就可以滑动了,这里特意记录一下,以备后面直接查看

            <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:background="@color/transparent"
                    app:elevation="0dp">
    
                    <com.google.android.material.appbar.CollapsingToolbarLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_scrollFlags="scroll|exitUntilCollapsed"
                        app:titleEnabled="false"
                        app:toolbarId="@+id/toolbar2">  <!-- toolbar2 这个就一直写着保留 -->
    
                        <!-- 这里写上面部分的布局 -->
                       <androidx.constraintlayout.widget.ConstraintLayout
                            android:id="@+id/clTopLayout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                        </androidx.constraintlayout.widget.ConstraintLayout>
    
                    </com.google.android.material.appbar.CollapsingToolbarLayout>
    
                      <!-- 这里写的是在上滑过程中,会一直悬停在顶部的部分,比如标题部分 -->
                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginHorizontal="@dimen/dp_10"
                        android:layout_marginTop="3dp"
                        android:background="@drawable/bg_r15_top_fff">
    
                    </androidx.constraintlayout.widget.ConstraintLayout>
    
                </com.google.android.material.appbar.AppBarLayout>
                <!-- 这里就是你下面很大一部分的列表或者其他布局了,可以一直网上滑动的内容 -->
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/newRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginHorizontal="@dimen/dp_10"
                    android:background="@drawable/bg_r15_bottom_fff"
                    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:spanCount="2"
                    tools:itemCount="4"
                    tools:listitem="@layout/item_list_two_soft_layout" />
    
            </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    如果 你想在屏幕顶部一直显示一些内容的话,可以在CoordinatorLayout 容器外,在加一层容器布局,然后让CoordinatorLayout 位置调整在它的下方就行了。

    相关文章

      网友评论

          本文标题:Android CoordinatorLayout+AppBa

          本文链接:https://www.haomeiwen.com/subject/pejuprtx.html