ok 首先我們來(lái)看看是不是咱們想要的效果!免得浪費(fèi)大家時(shí)間

效果圖.gif
這里采用CoordinatorLayout+AppBarLayout配合使用
再來(lái)看一下布局結(jié)構(gòu)

布局結(jié)構(gòu).jpg
現(xiàn)在要使用的話則Copy一下代碼稍作修改即可
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_two">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
boy:layout_scrollFlags="scroll|exitUntilCollapsed"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/dp_200"
android:src="@mipmap/testimage" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_topview"
android:layout_width="match_parent"
android:layout_height="116dp"
android:gravity="right"
android:background="@color/color_three"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:background="@color/color_two"
android:layout_height="66dp"/>
<Button
android:id="@+id/btn_screen"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="篩選" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/reclerview"
android:layout_width="match_parent"
boy:layout_behavior="@string/appbar_scrolling_view_behavior"
boy:layout_scrollFlags="scroll"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
這里需要注意一點(diǎn)的是
1.design這個(gè)包版本需要在26以上,不然有點(diǎn)卡頓,加速度有點(diǎn)問(wèn)題
2.如果我們懸浮模塊以上的這部分布局很長(zhǎng),超過(guò)了一屏,那么我們需要給AppBar加一個(gè)判斷,如下
private int mI;
appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//為0時(shí)表示AppBarLayout完全顯示
mI = verticalOffset;
refreshLayout.setEnableRefresh(mI >= 0);
}
});
//外層我是用的一個(gè)刷新控件 SmartRefreshLayout
//https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md
好了這樣就大功告成了,這次是不是清楚了
回手掏 鬼刀一開(kāi)看不見(jiàn) 走位走位 哈哈 老鐵心心來(lái)一個(gè)
demo下載鏈接:點(diǎn)擊這里就ok,ps里面融云的包沒(méi)刪不用管