作者:李冰或李冰圆_862 | 来源:互联网 | 2023-05-18 00:33
今天想做一个滑动到屏幕顶端的就停在哪里大图title,搜了一下资料,其实so easy,直接上代码
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_match_parent"
android:layout_match_parent"
>
android:layout_match_parent"
android:layout_match_parent">
android:layout_match_parent"
android:fitsSystemWindows="true"
android:layout_wrap_content">
android:layout_match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_100dp">
android:id="@+id/view_pager_head"
android:layout_match_parent"
android:layout_match_parent">
android:background="#ff0000"
android:gravity="center"
android:text="我是需要固定的头头"
android:layout_match_parent"
android:layout_50dp" />
android:id="@+id/rec"
android:layout_match_parent"
android:layout_wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
大家看到这里使用的是RecyclerView,这个android 5.0推出来的心特性,试想一下换成listView 或者Gridview行不行呢?
答案是肯定不行的,listView 和GridView是android5.0之前推出了,和协调者布局一起使用时没有效果的,只能使用RecyclerView啦