【发布时间】:2022-09-26 13:16:12
【问题描述】:
我有如下布局
当 recyclerview 滚动时,我希望粘性标题粘在顶部。下面是我的xml
<?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=\".MainActivity\">
<com.google.android.material.appbar.AppBarLayout
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:background=\"@color/black\"
android:fitsSystemWindows=\"true\"
android:elevation=\"1dp\">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id=\"@+id/food_disc_collapsing_toolbar\"
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
app:layout_scrollFlags=\"scroll|enterAlways|snap\">
<LinearLayout
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:background=\"@drawable/bottom_curve\"
android:paddingBottom=\"22dp\"
app:layout_collapseMode=\"parallax\"
app:layout_collapseParallaxMultiplier=\"0.7\"
android:orientation=\"vertical\">
<TextView
android:layout_width=\"match_parent\"
android:layout_height=\"56dp\"
android:background=\"@color/teal_700\"
android:gravity=\"center\"
android:paddingTop=\"16dp\"
android:paddingBottom=\"16dp\"
android:text=\"Collapsable Text\"
android:textColor=\"@color/white\"
android:textSize=\"16sp\" />
<FrameLayout
android:id=\"@+id/masthead_container\"
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:layout_marginTop=\"56dp\" />
</LinearLayout>
<androidx.appcompat.widget.Toolbar
android:id=\"@+id/toolbar\"
android:layout_width=\"match_parent\"
android:layout_height=\"?attr/actionBarSize\"
app:layout_collapseMode=\"pin\"
android:background=\"@color/black\"
android:layout_marginTop=\"56dp\"
app:popupTheme=\"@style/ThemeOverlay.AppCompat.Light\" >
<TextView
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:text=\"Sticky Header\"
android:gravity=\"center\"
android:textColor=\"#fff\"
android:textSize=\"18sp\" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
app:layout_behavior=\"@string/appbar_scrolling_view_behavior\"
android:id=\"@+id/rv\"
android:layout_width=\"match_parent\"
android:background=\"@color/black\"
android:layout_height=\"wrap_content\"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
如果我将粘性文本从 collapsingToolBar 中移出,那么它将起作用。但定位很重要。它应该是
--可折叠文本
--粘滞文本
--框架布局
有人可以建议我在这里做错了什么吗?
标签: android android-coordinatorlayout